June 10, 2011 at 12:16 pm
Hello:
I have table1 who has fields: name, dd
I want to insert new name: Jenny, but use value of name: Rack
select * from table1 where name = 'Rack'
Name dd
Rack 2
Rack 4
Rack 1
Rack 33
Rack 44
I want insert Jenny to table1 and use Rack's dd value
Name dd
Jenny 2
Jenny 4
Jenny 1
Jenny 33
Jenny 44
How to accomplish it?
Your help is highly appreciated.
June 10, 2011 at 12:47 pm
Something like below?
CREATE TABLE #table1
(
name varchar(10),
dd int
)
INSERT INTO #table1
SELECT 'Rack', 2 UNION ALL
SELECT 'Rack', 4 UNION ALL
SELECT 'Rack', 1 UNION ALL
SELECT 'Rack', 33 UNION ALL
SELECT 'Rack', 44
INSERT INTO #table1
SELECT 'Jenny', t.dd
FROM #table1 t
WHERE t.name = 'Rack'
SELECT name, dd FROM #table1
June 10, 2011 at 2:34 pm
Yes. Thank you very much!
June 10, 2011 at 3:18 pm
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply