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.
| Author |
Topic |
|
outspaced
Starting Member
21 Posts |
Posted - 2006-11-17 : 10:11:23
|
Hi,I am using MSSQL and I want to do something like this:insert into peoplevalues (newid(), *value from names table* ) but I can't work out how to select the value from one table and insert it into another table in a single query. Using a subquery or combining with a select has not worked.Is this a job for a datacursor or is there a simpler way?Thanks. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 10:15:59
|
insert into people (columns)select columnsfrom tableGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
outspaced
Starting Member
21 Posts |
Posted - 2006-11-17 : 10:19:39
|
| Thanks for the response.How do I combine that with some static values?eg insert into peoplevalues (newid(), *value from names table*, 'human', 'has 2 feet' ) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 10:31:57
|
insert into people (corresponding columns to insert into)select newid(), columnsFromTable, 'human', 'has 2 feet',...from tableGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
outspaced
Starting Member
21 Posts |
Posted - 2006-11-17 : 11:10:27
|
| Thanks for that - stupidly using the word values.Is there nay way I can sneak a distinct into there?eg:insert into people (corresponding columns to insert into)select newid(), distinct name, 'human', 'has 2 feet',...from nameswhere nameid in (1, 2 3)Cheers! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 11:18:25
|
insert into people (corresponding columns to insert into)select newid(), name, 'human', 'has 2 feet',...from(select distinct name, other columnsfrom nameswhere nameid in (1, 2 3)) t1Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
outspaced
Starting Member
21 Posts |
Posted - 2006-11-17 : 11:51:58
|
| Excellent, thanks very much for your help! |
 |
|
|
|
|
|
|
|