Re: Assigning variables with SELECT statements

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Adam Machanic (amachanic_at_hotmail._removetoemail_.com)
Date: 09/08/04


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.
>
>



Relevant Pages

  • Re: Assigning variables with SELECT statements
    ... Columnist, SQL Server Professional ... SELECT @varname = colname FROM table WHERE ... ... but I am unable to use the syntax ... 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. ...
    (microsoft.public.sqlserver.server)
  • RE: Repost: Update Text datatype from Linked Server Problem
    ... > GroupBy with ANY aggregates is the result of using the non-ansi update ... > stick to ansi update syntax and the problems will go away. ... change that part of the execution plan (the GroupBy with ANY aggregate is ... The workaround is failing for me. ...
    (microsoft.public.sqlserver.programming)
  • Re: Dynamic recordset
    ... BTW, when I tried to join the two tables from the two different ... databases I got an error, so I found a workaround. ... is the following syntax possible at all? ...
    (microsoft.public.access.forms)
  • Re: DOS copying
    ... >'copy' and 'xcopy' commands dont like the syntax once the spaced folder names ... >are introduced - anyone know are workaround?? ... Wrap the path in quotes - eg ...
    (microsoft.public.windowsxp.general)
  • Assigning variables with SELECT statements
    ... is valid in SQL server, but I am unable to use the syntax ... As I have a workaround that works well, I'm not too concerned about this - ... John. ...
    (microsoft.public.sqlserver.server)