If you want to check the IF Exists dynamically, you can use the following code also. The difference is you don't have to create/drop a temporary table.
------------------------------
CREATE PROCEDURE sp_blah
(
@tblName NVARCHAR(100)
)
AS
declare @sql varchar(1024)
Set @sql='Select this From ' + @tblName
exec(@sql)
IF @@rowcount>0
Print 'EXIST'
ELSE
Print 'Not Exist'
------------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.