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 |
|
pras2007
Posting Yak Master
216 Posts |
Posted - 2009-04-28 : 21:22:19
|
| I want to create an insert statement that uses an input value from a previous record set.Example: --1st query statementSelect MAX(Date_Entered)FROM SampleWhatever the Max value for the Date_Entered field, it should be in my insert valueExample: --2nd query statementINSERT INTO Table(column1, column2)VALUES(value1, [Date_Entered]);How can I store the value of "date_entered" field from the previous record set and use that value in my insert statement?Please advice. Thanks. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-04-28 : 21:27:54
|
[code]-- declare a variabledeclare @Date_Entered datetimeSelect @Date_Entered = MAX(Date_Entered)FROM SampleINSERT INTO Table (column1, column2)VALUES (value1, @Date_Entered)or Combined in single statement, exampleINSERT INTO Table (column1, column2)SELECT <some constant value or variable here>, MAX(Date_Entered)FROM Sample[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pras2007
Posting Yak Master
216 Posts |
Posted - 2009-04-28 : 21:41:50
|
| Thanks for the quick response khtan! |
 |
|
|
|
|
|