|
-
Aug 29th, 2008, 11:28 AM
#1
Thread Starter
Frenzied Member
Check a parameter value in SRPOC
Well,
I am going through one of my SRPOCs and I have some doubt about one of its values. It goes like this :
Code:
Update tb_book
SET stockbalance = stockbalance-@qty
LimitAlert= Case
When stockBalance-@qty<re_orderLimit
THEN 1
ELSE 0
END
Now my question is:
Is @qty being deleted twice , in the Set... and in the When.... ?
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Aug 29th, 2008, 11:32 AM
#2
Re: Check a parameter value in SRPOC
I would think you would want this, so stockBalance is not decrement by qty twice
Code:
Update tb_book
SET stockbalance = stockbalance-@qty
LimitAlert= Case
When stockBalance < re_orderLimit
THEN 1
ELSE 0
END
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Aug 29th, 2008, 11:36 AM
#3
Re: Check a parameter value in SRPOC
First - you are missing a comma - right. That syntax won't fly...
But a field's value is "original" value everywhere you refer to it in a single UPDATE query. Just because it's one-line up in the query - that you are doing
stockbalance = stockbalance-@qty
The stockbalance is not reduced in the CASE statement - it's original value.
-
Aug 29th, 2008, 11:38 AM
#4
Re: Check a parameter value in SRPOC
Here is the proof - your use is shown in this post
Code:
Set NoCount On
Declare @Test Table (Value int, Alert int)
Insert into @Test values (10,0)
Declare @Qty int
Set @Qty=5
Update @Test Set Value=Value-@Qty, Alert=Case When Value<=0 Then 1 Else 0 End
Select * From @Test
Update @Test Set Value=Value-@Qty, Alert=Case When Value<=0 Then 1 Else 0 End
Select * From @Test
returns
Code:
Value Alert
----------- -----------
5 0
Value Alert
----------- -----------
0 0
-
Aug 29th, 2008, 11:40 AM
#5
Re: Check a parameter value in SRPOC
And the proper way to do it
Code:
Set NoCount On
Declare @Test Table (Value int, Alert int)
Insert into @Test values (10,0)
Declare @Qty int
Set @Qty=5
Update @Test Set Value=Value-@Qty, Alert=Case When Value-@Qty<=0 Then 1 Else 0 End
Select * From @Test
Update @Test Set Value=Value-@Qty, Alert=Case When Value-@Qty<=0 Then 1 Else 0 End
Select * From @Test
which returns
Code:
Value Alert
----------- -----------
5 0
Value Alert
----------- -----------
0 1
-
Aug 29th, 2008, 01:45 PM
#6
Thread Starter
Frenzied Member
Re: Check a parameter value in SRPOC
ok Sslamany,
So apart from the comma which is my typo, the SPROC is okay and it is deducting only once. More convinced now.
thanks.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Aug 29th, 2008, 02:54 PM
#7
Re: Check a parameter value in SRPOC
Yes
and Yes was to short a reply for the forum so I am forced to add this
-
Aug 29th, 2008, 03:55 PM
#8
Thread Starter
Frenzied Member
Re: Check a parameter value in SRPOC
Thanks
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|