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.
| Author |
Topic |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-01-25 : 04:14:24
|
| Hi i need a sql stored procedure i am currently using the select statement below, but i need to use a if exsits i think.i want select Alo_Qtyfrom tablewhere Alo_UserID = @UserID and Alo_Stock_Code = @StockCodebut if there is no record in the table that matches then i need to set Alo_Qty = 0any ideas what i need to do? |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-01-25 : 04:30:41
|
| Declare @Table table(id int, val int)INSERT @TableSelect 1,3 union allSelect 2,5 union allSelect 3,6 union allSelect 4,8 Declare @Val1 intDeclare @Val2 intIF EXISTS(select @Val1=val from @Table where id=2 ) BEGIN Print' Your logic ' ENDELSE BEGIN Set Alo_Qty = 0 ENDYou can take help from above code snippet. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-25 : 08:50:31
|
| SELECT ISNULL(t.Alo_Qty,0)FROM(select Alo_Qtyfrom tablewhere Alo_UserID = @UserID and Alo_Stock_Code = @StockCode)t |
 |
|
|
|
|
|