SQL Server | Other
Additional SQL Server features and topics not covered by specific categories
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi ,
i have below query but it shows syntex error
SET @Query = N' SELECT Clientid, clientname,' + @Columns2 + ', Total = ' +REPLACE(@pivv, ',[', '+[') + ' INTO #Tempsara
FROM
(
SELECT Clientid, clientname,toupupamount,CONVERT(VARCHAR,Posteddatekey)+''_Topup'' Typ FROM #TMP_DATEatt
UNION
SELECT Clientid, clientname,Deno ,CONVERT(VARCHAR,Posteddatekey)+''_DENOCOUNT'' Typ FROM #TMP_DATEatt AS P
) AS j
PIVOT
(
SUM(toupupamount) FOR Typ IN ('+ @pivv + ')
) AS p;
DECLARE @Newcol NVARCHAR(MAX)
Select @Newcol=Stuff((Select ''+''+Name FRom Tempdb.sys.columns Where Object_id=Object_id(''tempdb..#Tempsara'' ) AND Name Like ''%_Topup'' For Xml Path('''')),1,1,'''')
Select *,'+@Newcol+' AS TopupTotal from #Tempsara
DROP TABLE #Tempsara';
EXEC (@Query)
Additional SQL Server features and topics not covered by specific categories
but it shows syntex error
And which detailed error message do you get?
Use a PRINT command to validate your dynamic SQL result.