Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesHi, 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
Post Follow-up to this messageINSERT 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.
Post Follow-up to this messageHi 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. >
Post Follow-up to this messageRefering 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.
Post Follow-up to this message>> 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..
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread