-1

I need to pass a server-side parameter to my SqlDataSource SELECT IN-clause as follows (notice the parameter @InClause and it's location in the SQL-select that is defined in the aspx (for the SqlDataSource):

SELECT UID_REPORT, TXT_RPT_TEXT, TXT_RPT_NAME, TXT_RPT_ASPX_PAGE, TXT_RPT_TYPE 
FROM REPORTS WHERE (UID_REPORT IN (@InClause)) 
ORDER BY INT_SORT_ORDER

But this does not pass validation in the Test-Query operation. The '@InClause' parameter gets it's value from a HiddenField control. I want to set this value based on some conditions. for example If DIVISION=5 then @InClause would ="45,46" Else ="14,15". Any suggestions on how to pass the IN ( ... ) values by the hiddenfield.Value (which is a string, of course). Thanks.

2
  • This question again? vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm Commented Jan 5, 2016 at 18:55
  • I was searching for similar questions/answers within Stack-Overflow, not asking the internet. I marked @VR46 as the answer, although your link buries the solution within the six different methods under the context of stored procedures. Thanks. Commented Jan 5, 2016 at 19:49

1 Answer 1

1

You need split string function to do this

SELECT uid_report, 
       txt_rpt_text, 
       txt_rpt_name, 
       txt_rpt_aspx_page, 
       txt_rpt_type 
FROM   reports 
WHERE  uid_report IN (SELECT split_value 
                      FROM   Udf_splitstring(@InClause, ',')) 
ORDER  BY int_sort_order 

Check the below links to create a split string function

  1. http://sqlperformance.com/2012/07/t-sql-queries/split-strings
  2. http://www.sqlservercentral.com/articles/Tally+Table/72993/

or of-course you can use dynamic sql

3
  • Is your posted code working in ASPX page select command or inside a SQL-Server script window? The select-code I posted resides within a SqlDataControl in aspx code. Commented Jan 5, 2016 at 18:46
  • i dont have anything to validate Commented Jan 5, 2016 at 18:47
  • I used your posted SQL code within the SqlDataSource select-command within the aspx code and it worked perfectly. I have a splitString function in my dbo but I did not know I could embed it within the aspx page. I use it many times within stored procedures. Thanks. Commented Jan 5, 2016 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.