How to resolve this in sql
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
DECLARE @cols NVARCHAR(MAX), @query NVARCHAR(MAX);
SET @cols = STUFF(
(
SELECT DISTINCT
','+QUOTENAME(c.Name)
FROM ProperyInfo c where GameId=174 FOR XML PATH(''), TYPE
).value('.', 'nvarchar(max)'), 1, 1, '');
select @cols
SET @query = 'SELECT distinct CardId, '+@cols+'from ( select qry.CardId,Name,
Case when TypeId=4 then (case when Value=1 then ''Yes'' else ''No'' end) else Value end As DisplayValue From(
select CardId,Name,TypeId,Value from ProperyInfo P inner join
PropertyValues PV ON P.ProperyInfoId=PV.PropertyInfoId inner join
CardPropertyValue CV ON CV.PropertyId=PV.PropertyInfoId
and CV.PropertValue=PV.PropertyValueId
where GameId=174
and TypeId=1
union
select CardId,Name,TypeId,PropertValue from ProperyInfo P inner join
CardPropertyValue CV ON CV.PropertyId=P.ProperyInfoId
where GameId=174
and TypeId<>1)qry
)x pivot (max(DisplayValue) for Name in ('+@cols+')) p';
EXECUTE (@query)
the query out is
CardId Course Days Gender Place Relocate
16904 JAVA 20 Male trichy No
47967 JAVA 22 Male salem No
i am trying to save temp table using below SELECT * INTO #tmpSortedBooksFROM execute ( @query ) i am getting error, Please provide your suggestion