SELECT VARIABLE Number of columns
I am developing a web application(using asp.net + C#) where I have a checkboxlist of columns in a table(on SQL server). Lets suppose there is a table customer_info with columns: name, address,phone, website etc.
So, my checkboxlist would list all the columns in the table. User can select one or more columns to display. Suppose user chooses only name and phone number to be displayed then While displaying the records, I must only display the requested columns to the user. The choice can vary each time. How do I do this using stored procedure.
I have collected the selected columns by the user as a comma -separated variable: Eg: @columns would get value like 'name, address' for above example.
But when I use the query
SELECT @columns FROM customer_info
it displays something like this
... and so on. It doesn't display the actual value of the columns.
Any help regarding this problem will be greatly appreciated.