I have created a procedure which will output the INSERT script for a given table name. And in the procedure I am using this code:
DECLARE @owner VARCHAR(20) ,
@Database VARCHAR(50)
SELECT @owner = 'dbo' ,
@Database = 'Asmin'
SELECT sc.name
FROM sysobjects so
INNER JOIN syscolumns sc ON so.id = sc.id
INNER JOIN systypes st ON sc.xtype = st.xusertype
WHERE so.Name = 'Acisd'
But the problem I see is the procedure is in collection database and the table Acisd is in different database. So it’s returning me nothing when I execute procedure.
How to fix this?
To do this inside a stored procedure you need to use dynamic SQL. For example: