setting a variable using select @x=top 1 col from table order by col

  • I've got the following:

    declare @x as int;

    select @x=top 1 col from table order by col

    This gives a syntax error.

    Is there anything that can be used to change precedence like brackets in programming languages?

    I want 'top 1 col' to be treated as a unit.

    The following works fine:

    select top 1 col from table order by col

  • move the Top 1 before the @x, as in:

    declare @x as int;

    select top 1 @x=col from table order by col

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • That's great. It works.

    Thanks for the speedy response.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply