• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

SQL Query Select into

Good Day

Experts:

Started the day off with a little challenge that I need help with.  I have data in Table "A"  database "Production".  I would like to do a Select * from A where ID = '5' then I want to insert the results
into database "Test" table "A".

Is this possible since they tables are in different db's?   If so, how can I achieve this?

Thanks,
jimbo99999
0
Jimbo99999
Asked:
Jimbo99999
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Yes, notice the .. (might need to be .owner_name. if appropriate)

INSERT INTO Test..A (Column1, Column2, Column3, ColumnN)
SELECT pa.Column1, pa.Column2, pa.Column3, pa.ColumnN
FROM Production..A pa
WHERE pa.ID = 5
0
 
Jimbo99999Author Commented:
Thanks for the help.  I'll put that one in the back pocket for future use.
jimbo99999
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim

Keep in mind though, using this approach creates a dependancy on Production..A FROM Test..A.
If you ever change the schema in Production..A, you'll have to go fish and find everything that touches it, which now will be T-SQL on another db.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now