Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with variable

Author  Topic 

orenk
Starting Member

1 Post

Posted - 2013-05-31 : 07:11:39
Hey,

by running this code the variable @db_name will not be read in the select to set @diff



declare @diff nvarchar(10)
declare @db_name nvarchar(120)

set @db_name ='Olaf'

select @diff = datediff(day,max(datum),getdate()) from @db_name.dbo.xxaprot
insert into test_or.dbo.DBAlter values(@db_name,@diff)


What´s wrong? Or is there a way to do it otherway?

Thanks
Olaf

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-05-31 : 07:21:09
see here: http://www.sommarskog.se/dynamic_sql.html


Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -