|
Home > Archive > MS SQL Server New Users > November 2005 > Insert into another DB on the same server
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Insert into another DB on the same server
|
|
|
| I have database A and database B on the same server
I want to select from database A and create a new table in database B with
the results. This is my query as of now:
Select
userid, tempimmproapplicanti
d, improtype, linktothisapplicanti
d
from Users
where tempimmproapplicanti
d is not null
order by improtype
How can I add code to this query to insert it into database B, the name of
database B say is "DatabaseB"
Help is appreciated.
Aleks
| |
| Andrew J. Kelly 2005-11-29, 8:24 pm |
|
Select
userid, tempimmproapplicanti
d, improtype, linktothisapplicanti
d
--> INTO DatabaseB.dbo.YourNewTable
from Users
where tempimmproapplicanti
d is not null
--> order by improtype
Note the INTO line. This will create a new table in the structure of the
original columns selected. Please not also that the ORDER BY is useless in
this case. A table is an unordered set or rows regardless of how you insert
them. If you want the data out of that table in a specific order you must
use an order by on the select.
--
Andrew J. Kelly SQL MVP
"Aleks" <arkark2004@hotmail.com> wrote in message
news:ugKJnGT9FHA.2792@TK2MSFTNGP11.phx.gbl...
>I have database A and database B on the same server
>
> I want to select from database A and create a new table in database B with
> the results. This is my query as of now:
>
> Select
> userid, tempimmproapplicanti
d, improtype, linktothisapplicanti
d
> from Users
> where tempimmproapplicanti
d is not null
> order by improtype
>
> How can I add code to this query to insert it into database B, the name of
> database B say is "DatabaseB"
>
> Help is appreciated.
>
> Aleks
>
|
|
|
|
|