By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,414 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,414 IT Pros & Developers. It's quick & easy.

how to make SQL commands more dynamic?

P: 200
Suppose I have this
Expand|Select|Wrap|Line Numbers
  1. SELECT * INTO [db1].[clroot].[test] FROM [db2].[clroot].[test];
can I set the source/destination database.owner.tablename as variables and then just the variables names in the select command?
generally tried
Expand|Select|Wrap|Line Numbers
  1. declare @a char(50)
  2. set @a='[clroot].[test]'
  3. select * from @a
but didn't worked
PS It is true that using variables inside the select will make my queries many times more slower and if this is not the best practice what would be your advice for having around 50 'insert into' statements to be easily to change source and destination databases?
Mar 11 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 2,878
use this technique...

-- CK
Mar 12 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.