Can anyone check my expression ...
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 mistake...
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@tblName".
What I want to do is get the table name in the variable @tblNameand insert some data into the variable@strSQL
For example, the result in @tblNameisCustomerInfo
then in @strSQLi'm going to use the result in @tblNameas the name of my table in my insert command.
So the variable @strSQLwill be;
INSERT INTO CustomerInfo VALUES(......)
source
share