Re: Assigning variables with SELECT statements
From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 09/08/04
- Next message: Anith Sen: "Re: Assigning variables with SELECT statements"
- Previous message: Andrew J. Kelly: "Re: Raid 1 vs Raid 10"
- In reply to: John McLusky: "Assigning variables with SELECT statements"
- Next in thread: Anith Sen: "Re: Assigning variables with SELECT statements"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 8 Sep 2004 14:04:01 -0400
John,
You were so close...
SELECT TOP 1 @varname = colname FROM table WHERE ...
"John McLusky" <jmclusky@community.nospam> wrote in message
news:%23yfS71clEHA.3372@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> The syntax
>
> SELECT @varname = colname FROM table WHERE ...
>
> is valid in SQL server, but I am unable to use the syntax
>
> SELECT @varname = TOP 1 colname FROM table WHERE ...
>
> which would be useful if (for example) getting the most recent index
number
> from a table using an ORDER BY clause (e.g. ORDER BY entry_date DESC)
>
> I can use a workaround such as
>
> SET @varname = (SELECT TOP 1 colname FROM table WHERE ...)
>
> As I have a workaround that works well, I'm not too concerned about this -
> just wondering if I'm missing something with the syntax that causes my
> second example to fail.
>
> John.
>
>
- Next message: Anith Sen: "Re: Assigning variables with SELECT statements"
- Previous message: Andrew J. Kelly: "Re: Raid 1 vs Raid 10"
- In reply to: John McLusky: "Assigning variables with SELECT statements"
- Next in thread: Anith Sen: "Re: Assigning variables with SELECT statements"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|