Dynamic Stored Procedure RRS feed

  • Question

  • User828132996 posted

    I wrote a Stored Procedure to Filter records in my GridView. I have a dropdown list with 4 items and used  IF/ELSE statements to determin what to Filter by. 


    IF @SearchBy = 'PatientCity'

    Select .....

    ELSE IF @SearchBy = 'PatientState'

    Select ....


    This gets redundant because the select statements are excatly the same. Just filtering by either City, State, etc.

    As of now I have 4 IF/ELSE IF statements and 4 of the same SELECT Statements. What I would like to do is some how use just 1 IF statement that could some get the value from my dropdown list and the display the SELECT according to what is Selected from my dropdown list. 

    Is there a way to some how do this:

    IF @SearchBy = ''

    Select ...

    Wednesday, November 20, 2013 10:21 AM