2021年4月28日星期三

Correct way to execute SQL Query like Select * from @database_name.dbo.table1

i've declared my database name and need to execute it in a query so i don't have to type the name every time. It looks like this:

DECLARE @db_source varchar(255), @db_target varchar(255)  SET @db_source   ='database1'  SET @db_target   ='database2'  

--Now i want to insert value into @db_target by select data from a table in @db_source

Insert into @db_target.dbo.table1 (field1,field2)  select (field1,field2) from @db_source.dbo.table1  where <some conditions>   

-- but I got error everytime i execute the query -- how to fix it?

https://stackoverflow.com/questions/67310413/correct-way-to-execute-sql-query-like-select-from-database-name-dbo-table1 April 29, 2021 at 10:56AM

没有评论:

发表评论