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 |
|
sahu74
Posting Yak Master
100 Posts |
Posted - 2002-07-22 : 11:35:45
|
| I need to insert some values like year, collegecode,...etcI know some of the values and have to use select statements for the others. How can I insert a row with the values and select statements together.PKS. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-07-22 : 11:52:58
|
| Here's an example:CREATE TABLE Things (yearCol int, collegeCode varchar(3), FirstName varchar(15), LastName varchar(20) )GODECLARE @yr int, @code varchar(3)SELECT @yr=2001, @code='USC' --set values for the variablesINSERT INTO Things (yearCol, collegeCode, FirstName, LastName)SELECT @yr, @code, FirstName, LastNameFROM StudentsWHERE College='USC' AND Year(GraduationDate)=2001The parameters are simply included in the SELECT list, and they correspond to the yearCol and collegeCode columns indicated in the INSERT list. |
 |
|
|
|
|
|
|
|