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
 Insert Statement

Author  Topic 

psangeetha
Yak Posting Veteran

95 Posts

Posted - 2008-03-24 : 19:42:17
Hi all,

I know its a very basic question, but need some help from the experts here. I will have to insert a record into a table, where value of one column will be from the input of an output of a select statement. I used & in the insert statement in oracle to manually give the input for one of the column in the table.
Not sure how I can do this in SQL server. Any suggestions?
Thanks much!

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-03-24 : 23:38:31
insert ... table1 select ... from table2 where ...
Go to Top of Page

psangeetha
Yak Posting Veteran

95 Posts

Posted - 2008-03-25 : 08:42:17
But I cannot use insert from select statement because I have to get only one column value from another table and rest of the columns are given values(meaning I have to insert). Tricky part is I cannot insert the columns in seperate statements like inserting one column from select and other two manually because they are not null columns.
Hope I not confusing this.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-25 : 08:47:58
ALTER TABLE #Target ADD MyNewColumn INT

UPDATE t
SET t.MyNewColumn = s.MyNewValue
FROM #Target AS t
INNER JOIN (my source description here) AS s ON s.MyPkCol = t.MyPkCol



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -