August 25, 2010 at 7:34 pm
Mentioned below is my sql. @server and @database are created dynamically. I need to get name,type_desc,create_date,modify_date,@server and @database columns in one table. Any suggestions?
select name,type_desc,create_date,modify_date from [' + @server + '].[' + @database + '].sys.views
where create_date > ''2010-08-24''
order by modify_date desc
August 25, 2010 at 10:18 pm
iqtedar (8/25/2010)
Mentioned below is my sql. @server and @database are created dynamically. I need to get name,type_desc,create_date,modify_date,@server and @database columns in one table. Any suggestions?select name,type_desc,create_date,modify_date from [' + @server + '].[' + @database + '].sys.views
where create_date > ''2010-08-24''
order by modify_date desc
declare @sql_cmd varchar(max);
set @sql_cmd = 'select name,type_desc,create_date,modify_date from [''' + @server + '''].[''' + @database + '''].sys.views
where create_date > ''2010-08-24''
order by modify_date desc'
exec (@sql_cmd);
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 26, 2010 at 8:14 am
thanks for the reply. Not sure whats the difference between yours and mine . Your doesn't work. Thanks
August 26, 2010 at 9:24 am
I see I forgot to comment what I was doing.
Since the server/db are in variables, you need to build a string to put the variables in. Then execute the string.
And, I see that the quotes inside the brackets shouldn't be there.
So, this is working for me:
declare @sql_cmd varchar(max);
set @sql_cmd = 'select name,type_desc,create_date,modify_date from [' + @server + '].[' + @database + '].sys.views
where create_date > ''2010-08-24''
order by modify_date desc'
print @sql_cmd
exec (@sql_cmd);
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 27, 2010 at 1:36 pm
thanks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply