x

sql command

Table:product

product_id   parent_id
966          0   

If the table value like this

insert row and value into Table:custom

more ▼

asked Aug 08, 2012 at 03:37 AM in Default

Yan0609 gravatar image

Yan0609
0 1 2

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Seems like you need something like the following

INSERT custom (COL1NAME, COL2NAME....OTHER COLUMNS)
SELECT product_id, parent_id... OR ANY COLUMNNAMES
FROM product
WHERE product_id = 966 AND parent_id = 0
more ▼

answered Aug 08, 2012 at 05:32 AM

Usman Butt gravatar image

Usman Butt
13.9k 6 8 14

If I don,t kNow which project id I just want to insert. The Id which is parent id =0
Aug 08, 2012 at 06:12 AM Yan0609

@Yan0609 Can you please give some test data and desired output to sort this out? But if I understand you correctly, you mean you just need to insert those rows where parentid = 0, then change the WHERE clause from

WHERE product_id = 966 AND parent_id = 0

to

WHERE parent_id = 0
Aug 08, 2012 at 06:33 AM Usman Butt
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x987
x107

asked: Aug 08, 2012 at 03:37 AM

Seen: 425 times

Last Updated: Aug 08, 2012 at 07:21 AM