Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello Everybody,How to insert data in temp table. If i have fields names [From],[To],[Cc]. Tables field names are store on variables.Declare @Schema VARCHAR(20)Declare @TableName VARCHAR(25)Declare @PkID VARCHAR(25)Declare @From VARCHAR(25)Declare @To VARCHAR(25)Declare @Cc VARCHAR(25)SET @Schema='DBO'SET @TableName='tbl1'SET @PkID='ID'SET @From='From'SET @To='To'SET @Cc='Cc' SELECT @PkID, [@From],[@To],[@Cc] INTO #Temp FrOM @Schema+'.'+ @TableName WHERE [@From] IS NOT NULLSELECT * From #TempDROP table #Temp
Even i trie this i can not get result:I got the error Declare @Schema VARCHAR(20)Declare @TableName varchar(25)Declare @ID VARCHAR(25)Declare @From VARCHAR(25)SET @Schema='dbo'SET @TableName='tbl1'SET @ID='ID'SET @From='From'select @id,[@from] from @Schema+'.'+@TableName
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts
Posted - 2009-03-26 : 16:30:48
You are not using it right. Go thru this article,,http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-1