isaac.a (1/24/2011)
beginDECLARE @deldate varchar(10)='01/01/1960',
@tblname varchar(50) = 'CACCOUNTSTMT',
@ssql varchar(200)
set @ssql = 'set @deldate = (select max(Convert(varchar(10) ,RowCreateDate,103)) from ' +@tblname +')'
print @ssql
--set @deldate = @ssql
exec(@ssql)
print 'deledate'
print @deldate
end
gives the following error
Must declare the scalar variable "@deldate".
can any one help on this?
In the dynamic sql, you are setting a variable that doesn't exist in the context of the dynamic sql connection.
Use the solution David supplied to pass it in and get the results back out.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes