sql - What strategies can I use to dynamically choose which column to filter on? -
i want pass t-sql stored procedure 2 integer values, used determine columns i'll utilize in clause. table involved 4 columns in named q1, q2, q3 , q4. if pass in 1 first integer , 3 sec integer, want utilize q1 , q3. i'm not sure how go doing that, utilize help, please.
send in indices list , dynamic sql string.
select <columnlist> <table> (1 in @indices , column1 = @value) or (2 in @indices , column2 = @value) or (3 in @indices , column3 = @value) or (4 in @indices , column4 = @value)
or using pattern, matches (incompletely specified) logic.
or utilize 2 parameters , create conditions this, if you're sure there ever 2 parameters...
select <columnlist> <table> ((1 = @index1 or 1 = @index2) , column1 = @value) or ((2 = @index1 or 2 = @index2) , column2 = @value) or ((3 = @index1 or 3 = @index2) , column3 = @value) or ((4 = @index1 or 4 = @index2) , column4 = @value)
sql sql-server
No comments:
Post a Comment