How to Retrieve Dynamic Columns?
- by user2514925
I have a table:
EmpId FirstName LastName Domain Vertical Account City
345 Priya Palanisamy DotNet LS Abbott Chennai
346 Kavitha Amirtharaj DotNet CG Diageo Chennai
647 Kala Haribabu DotNet IME IMS Chennai
I want to take the particular columns dynamically. I am using the following procedure but I can take only one column at a time:
create PROC columnlist
(
@COLUMNS VARCHAR(1000)
)
AS
BEGIN
DECLARE @sql nvarchar(max) = 'SELECT '+ @COLUMNS + ' FROM Table';
exec sp_executesql @sql,N''
END