SQL Renaming a column of a temp table

SamBa1927 1 Reputation point

I can't get what is not working in the below bold highlighted line. I would be grateful to anyone who could help me!

DECLARE @AssetWithDrawStartDate DATE;
DECLARE @AssetWithDrawDate DATE;
DECLARE @TradeStartDate DATE;
SET @AssetWithDrawDate= GETDATE()
SET @AssetWithDrawStartDate = dateadd(day,-7,@AssetWithDrawDate)
SET @TradeDate= GETDATE()
SET @TradeStartDate = dateadd(day,-30,@TradeDate)
SELECT DateTime, Asset, ClientId, Volume
INTO #TempWithdraw FROM dbo.cashoperations
EXEC SP_RENAME '#TempWithdraw.[DateTime]' , '[Dat]', 'COLUMN'
SELECT * FROM #TempWithdraw
Where Datetime >= @AssetWithDrawStartDate and [DateTime] <= @AssetWithDrawDate

SQL Server on Azure Virtual Machines
Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 33,421 Reputation points MVP

    Please try the following:

    EXEC tempdb.sys.sp_rename N'#TempWithdraw.DateTime', N'Dat', N'COLUMN';  

    You need to invoke sp_rename from TempDB.

    0 comments No comments