Declaring SQL variables - SQL Server
-
29-10-2019 - |
Question
Can anyone check on my statement...
DECLARE @tblName varchar(MAX),
@strSQL varchar(MAX)
SET @tblName ='SELECT DISTINCT o.name as TableName
FROM sysobjects o
JOIN sysindexes x on o.id = x.id
WHERE o.name LIKE ''%empty%'''
SET @strSQL = 'INSERT INTO @tblName VALUES(''trylng'', ''1'')'
EXEC (@strSQL)
my error is...
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@tblName".
What I want to do is get the table name on the variable @tblName
and insert some data in @strSQL
variable
For example... the result in @tblName
is CustomerInfo
then in @strSQL
I will going to use the result in @tblName
as my table name in my Insert Command.
So the @strSQL
variable will be;
INSERT INTO CustomerInfo VALUES(......)
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow