I have a variable in SQL Server:
DECLARE @cols AS NVARCHAR(MAX);
Variable @cols
contains these values:
[Afghanistan],[Australia],[Bangladesh]
Somewhere in a stored procedure, I have this SQL statement:
SELECT ID, AccountTypeName AS Type
FROM cte AS t
I want this SQL satement to execute with the column names stored in @cols
-
like this
SELECT ID, AccountTypeName, [Afghanistan], [Australia], [Bangladesh],[England] AS Type
FROM cte AS t
My problem is I am using a CTE.