sql server - Dynamic SQL / Parameters / Search -
i have searched on forum , found examples of how can send list of comma separated values sql , process them.
i wanted know if can create dynamic parameters , pass them stored procedure or better way of making particular task easier?
i take string , create array of 'space' separated values , each of values create new parameter (eg searchtext0, searchtext1, etc).
for each item in searchstring parameters.(new sqlparameter("@searchtext" + array.indexof(searchstring, item).tostring, item))) next the problem occurs when running stored procedure if there many parameters created array sp not execute, little works fine can treat parameter empty value.
@susercode varchar (10) = '', @searchtext1 varchar (300) = '', @searchtext2 varchar (300) = '', @searchtext3 varchar (300) = '', @searchtext4 varchar (300) = '' begin select top (20) prodtbl.material + ' | ' + prodtbl.description + ' [' + prodtbl.plant + ']' mat, prodtbl.material, prodtbl.description, prodtbl.plant scodes inner join prodtbl on scodes.plant = prodtbl.plant (scodes.usercode = @susercode) , (prodtbl.bin <> 'dscntd') , (prodtbl.material '%' + @searchtext1 + '%' or prodtbl.description '%' + @searchtext1 + '%' or prodtbl.plant '%' + @searchtext1 + '%' or prodtbl.manuf '%' + @searchtext1 + '%') , (prodtbl.material '%' + @searchtext2 + '%' or prodtbl.description '%' + @searchtext2 + '%' or prodtbl.plant '%' + @searchtext2 + '%' or prodtbl.manuf '%' + @searchtext2 + '%') , (prodtbl.material '%' + @searchtext3 + '%' or prodtbl.description '%' + @searchtext3 + '%' or prodtbl.plant '%' + @searchtext3 + '%' or prodtbl.manuf '%' + @searchtext3 + '%') , (prodtbl.material '%' + @searchtext4 + '%' or prodtbl.description '%' + @searchtext4 + '%' or prodtbl.plant '%' + @searchtext4 + '%' or prodtbl.manuf '%' + @searchtext4 + '%') end i know can write command string , run like able not worry having touch vbcode , make changes stored procedure.
there around 50 columns , want allow users search around 10 of them without making sp huge , without having add new row every potential parameter created in vbcode.
thanks in advance. kev
Comments
Post a Comment