Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Insert based on a select query
Hi,

I have a SQL query:

select products.name, products.notes, products.purchase_date,
products.serial_no, products.total_value, products.product_code,
products.quantity, products.product_group, products.lhs1_name,
lhs1.department, lhs1.address1, lhs1.city, lhs1.country
from products, lhs1
where products.lhs1_id = lhs1.id

I want to insert the results of this query into a table called 'temp' in the
database. I used to copy and paste this into excel then import it but it
doesn't always work.

Is there a way to do it all in a SQL script. Please be aware that my
knowledge of SQL is fairly basic so please explain things clearly.

Thanks,

Darren



Report this thread to moderator Post Follow-up to this message
Old Post
Mintyman
09-20-05 02:23 PM


Re: Insert based on a select query
INSERT INTO Temp
select products.name, products.notes, products.purchase_date,
products.serial_no, products.total_value, products.product_code,
products.quantity, products.product_group, products.lhs1_name,
lhs1.department, lhs1.address1, lhs1.city, lhs1.country
from products, lhs1
where products.lhs1_id = lhs1.id

if it does not exists at runtime:

SELECT
products.name, products.notes, products.purchase_date,
products.serial_no, products.total_value, products.product_code,
products.quantity, products.product_group, products.lhs1_name,
lhs1.department, lhs1.address1, lhs1.city, lhs1.country
from products, lhs1
where products.lhs1_id = lhs1.id
INTO Temp


HTH, Jens Suessmeyer.


Report this thread to moderator Post Follow-up to this message
Old Post
Jens
09-20-05 02:23 PM


Re: Insert based on a select query
Hi Jens,

Thanks for the quick reply. Your help is much appreciated. What would I need
to do in order to insert the results into a table called 'temp' that resides
in a different database e.g. Logi?

Thanks

"Jens" <Jens@sqlserver2005.de> wrote in message
news:1127219694.666930.255500@f14g2000cwb.googlegroups.com...
> INSERT INTO Temp
> select products.name, products.notes, products.purchase_date,
> products.serial_no, products.total_value, products.product_code,
> products.quantity, products.product_group, products.lhs1_name,
> lhs1.department, lhs1.address1, lhs1.city, lhs1.country
> from products, lhs1
> where products.lhs1_id = lhs1.id
>
> if it does not exists at runtime:
>
> SELECT
> products.name, products.notes, products.purchase_date,
> products.serial_no, products.total_value, products.product_code,
> products.quantity, products.product_group, products.lhs1_name,
> lhs1.department, lhs1.address1, lhs1.city, lhs1.country
> from products, lhs1
> where products.lhs1_id = lhs1.id
> INTO Temp
>
>
> HTH, Jens Suessmeyer.
>



Report this thread to moderator Post Follow-up to this message
Old Post
Mintyman
09-20-05 02:23 PM


Re: Insert based on a select query
Refering to the four part notation this is gernerally:

[servername].[databasename].[owner].[objectname]

SELECT
products.name, products.notes, products.purchase_date,
products.serial_no, products.total_value, products.product_code,
products.quantity, products.product_group, products.lhs1_name,
lhs1.department, lhs1.address1, lhs1.city, lhs1.country
from products, lhs1
where products.lhs1_id = lhs1.id
INTO logi..Temp

HTH, Jens Suessmeyer.


Report this thread to moderator Post Follow-up to this message
Old Post
Jens
09-20-05 02:23 PM


Re: Insert based on a select query
>>  Products.lhs1_id = lhs1.id  <<

Why did a data element change names from table to table?   Why do so
many of your data elements violate the rules of data modeling and
ISO-11179?

I would bet that this magical table, Temp, is not needed but is used to
mimic a scratch tape in a procedural solution.  It is a common Newbie
error.  You probably ought to get some help on the entire schema.

Otherwise, go to BOL and look up INSERT INTO .. SELECT..


Report this thread to moderator Post Follow-up to this message
Old Post
--CELKO--
09-21-05 12:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 02:23 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006