Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from Select
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01673282
Message ID:
01673311
Views:
37
>>One more question (hopefully, for your sake :), last one for today. Your code (below) works.
>>
>>declare @QtyUse as Int;
>>set @QtyUse = 1;
>>update t1 set t1.qty_left = t1.qty_left -  @QtyUse 
>>from myTable t1
>>inner join
>>(select top (1) t2.pk from MyTable t2 where t2.rec_id = '1' 
>> order by t2.date_rec) t2 on t1.pk = t2.pk
>>
>>
>>The only thing is, how do I determine that no record is found in the Select top(1) clause? So, that I can exit the While?
>
>I missed that question.
>
>Use
>
>IF @@ROWCOUNT = 0 condition
>--------------------------
>@@ROWCOUNT variable is updated after each statement, so it should be the next check right after UPDATE.

Thank you!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform