I have data in the SQL 2005 table as below.
Table Name: FilterData CategoryID ColumnID AnswerCode -------------------------------- 0349 Q15 02 0349 Q15 03 0349 Q16 04
Table Name: TransactionData CategoryID Q15 --------------------------------- 0349 01 0349 02 0349 03 0349 04 0349 05 0349 06
FilterData table has information about what columns will be used to filter select statements on TransactionData. So when i execute Select * from TransactionData, i want to build Where Clause from FilterData table so that i can fire it on TransactionData table for that CategoryID.
Can someone please help me out that how can i do this?
If I understand your question correctly, the code below should work. Note that I’ve created a function to help with the string concatenation. I’m not sure if you wanted to AND or OR your conditions. I’ve used AND in my sample. You can easily adjust it for OR if that’s appropriate.