Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL IF QuantityReceived > Quantity THEN

Author  Topic 

calvinfoo
Posting Yak Master

129 Posts

Posted - 2010-12-22 : 22:35:40
Hi,

ItemDesc = Pencil
Quantity = 100
QuantityReceived = null

User can key in the Quantity Received, then I will update the record accordingly.

Example:
Existing Quantity is 100
@Received
if user entered @received < Quantity, then update the QuantityReceived = @received;
if user entered @received >= Quantity, then update the ReceivedQuantity = Quantity

How is the SQL Command looks like for IF THEN ELSE?




calvinfoo
Posting Yak Master

129 Posts

Posted - 2010-12-22 : 22:51:17
Hi,

I just figured out the answer:

update table_name set QuantityReceived = CASE WHEN 100 > Quantity THEN Quantity ELSE 100 END
Go to Top of Page
   

- Advertisement -