Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to append to table and add literal

Author  Topic 

gwunta
Starting Member

2 Posts

Posted - 2011-03-09 : 10:57:57
Hi guys, Ive had very little experience with SQL and am trying to work out how to copy the contents of a field matching a certain criteria into another table AND adding a literal value for each row in the destination table.

IE
TABLE_DEST
PRODUCTID, PRODUCT_TYPE_ID

Where each value in the PRODUCTID field would be copied from TABLE_SRC based on some criteria and then the value 9 lets say, be entered into the PRODUCT_TYPE_ID field.

This is what I have at the moment

INSERT INTO jos_vm_product_product_type_xref (product_id,product_type_id)
SELECT product_id
FROM jos_vm_product
WHERE attribute like 'Size,One%','9'

Any help would be very much appreciated

Thank you in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-03-09 : 11:01:36
[code]
INSERT INTO jos_vm_product_product_type_xref (product_id,product_type_id)
SELECT product_id,'9'
FROM jos_vm_product
WHERE attribute like 'Size,One%'
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gwunta
Starting Member

2 Posts

Posted - 2011-03-09 : 11:09:43
Thankyou so so much, I wasnt far off the mark after all. VERY much appreciated.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-03-09 : 11:18:40
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -