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 |
|
Heinz23
Yak Posting Veteran
84 Posts |
Posted - 2008-12-30 : 12:03:44
|
Hi all,ok, I could use TOP 1 to get only 1 row back, but this does not seem to work when I want to store the result in a variable, or I'm using a wrong syntax.So I have a select like: SELECT PostedDate From POSTS Where UserID = 1 ORDER BY PostedDate DESCHow could I store it in a variable? Like: SET @LastPost = PostedDate From POSTS Where UserID = 1 ORDER By PostedDate DESC ?I've seen that I could use 'ORDER BY PostedDate ASC' and then I get the last value, probably because the SELECT is continously overwriting its result? However, I guess this is not the best solution so maybe someone could give me a short hint?Many thanks! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 12:15:49
|
| [code]SELECT TOP 1 @LastPost = PostedDate From POSTS Where UserID = 1 ORDER BY PostedDate DESC[/code] |
 |
|
|
Heinz23
Yak Posting Veteran
84 Posts |
Posted - 2008-12-30 : 13:45:12
|
| Hi Tara, visakh,thanks a lot, of course this works fine!Best regards! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-30 : 13:48:45
|
| welcome |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|