A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

  • I'm using a self incrementing loop on a table which I do quite a lot to process some data, however, this time I'm getting the error message above, the code is basically:

    DECLARE @ID int

    SELECT @ID = MIN(URN)

    FROM [tablename]

    WHILE ISNULL(@ID,0) > 0

    BEGIN

    SELECT @ID = MIN(URN)

    FROM [tablename]

    WHERE URN > @ID

    END

    The URN field is a Unique Int, anyone have any idea why it's throwing an error?

  • No error in that code that I can spot... What error are you getting?

  • A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

    Tres bizarre.

  • Oh, I think it means that you are doing something like this :

    Select @MyVar = min(MyCol), MyCol2 from...

     

    You cannot mix opening a dataset and setting variables at the same time. (well you can but not in that case ).

     

    Please post the actual code next time assuming you can... it's easier to spot the error that way.

  • The error was on a line about 50 lines before the one it was reporting, I'd forgotten to add an @ to the beginning of one of my variables when I was creating them directly from a table with a conditional URN = @ID statement.

  • Ya that happens... a no error statement that really is an error .  That's why debugging was invented.

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

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