Problem with trigger

  • Declare @a as int

    SET @a = null

    Declare @Tbl table (Col int primary key clustered)

    insert into @Tbl (col) values (2)

    insert into @Tbl (col) values (6)

    insert into @Tbl (col) values (1)

    insert into @Tbl (col) values (9)

    Select @a = col from @Tbl

    Select @a

    --9

    insert into @Tbl (col) values (56)

    Select @a = col from @Tbl

    Select @a

    --56

    --and to proove you right :

    Select @a = col from @Tbl order by col desc

    Select @a

    --1

    Select @a = col from @Tbl order by newid()

    Select @a

    --2

    The fact is when you do Select @val = SomeCol from SomeObject. It will be set to the last value of that set in that time or it will remain to its original value of the set is empty.

    I don't wanna restart the order by thingy in set as we both know it's the only garantee to have the order by you need in a set.

Viewing post 16 (of 15 total)

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