SQL存储过程 [英] SQL Stored procedures
本文介绍了SQL存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能否告诉我为什么这在SQL中不起作用
更改 ProCEDURE SD @ Orderid int , @ Scaleno int , @ Sex Varchar ( 1 ), @ Breed Varchar ( 3 ), @ Moves < span class =code-keyword> int , @ FQA varchar ( 1 ), @ Months int
< span class =code-keyword> AS
开始
声明 @ Dest Varchar ( 3 )
选择 案例 @ Sex
当 ' A' 然后
如果 @ FQA = ' Q' 和 @ Moves < 4 @ Months < 16 @ Breed <> ' FR' 和 @ Breed <> ' FRX' @ Dest = ' SA'
当'B'
等等等
它像if语句一样
我正在尝试根据传递给商店程序的信息设置一个标志
想想我也这样做vb ish
谢谢
解决方案
这是你的意思吗?
假设你正在测试@sex ='A'以及其他条件。
我希望这会有所帮助。
Don
< pre lang =sql> 更改 ProCEDURE SD @ Orderid int , @ Scaleno int , @ Sex Varchar ( 1 ), @ Breed Varchar ( 3 ) , @ Moves int , @ FQA < span class =code-keyword> varchar ( 1 ), @ Months int
AS
开始
声明 @ Dest Varchar ( 3 )
if ( @ FQA = ' Q'
和温泉n> @ Moves < 4
@ Months < 16
@ Breed <> ' FR'
和 @ Breed <> ' FRX'
和 @ Sex = ' A')
开始
set @ Dest = ' SA'
end
end
< span class =code-comment> / *
exec SD 0,0,'A','BG',2,'Q',10
exec SD 0,0,'B','BG',2,'Q',10
exec SD 0,0,'A','BG',4,'Q',10
* /
创建 PROC spSD @ Orderid int , @ Scaleno int , @ Sex Varchar ( 1 ), @ Breed Varchar ( 3 ), @ Moves int , @ FQA varchar ( 1 ), @ Months int
AS
开始
声明 @Dest nvarchar ( 3 )
set @ dest = case
<跨度class =code-keyword>当 @ Sex = ' A' 然后
case when @ FQA = ' Q' @ Moves < 4 @ Months < 16 @ Breed <> ' FR' 和 @ Breed <> ' FRX' 然后
' SA'
else
' BL2'
end
else
' BLH'
end
选择 @ Dest ;
结束
can you please tell me why this doesn't work in SQL
Alter ProCEDURE SD @Orderid int, @Scaleno int, @Sex Varchar(1), @Breed Varchar(3), @Moves int, @FQA varchar(1), @Months int
AS
Begin
declare @Dest Varchar(3)
Select Case @Sex
When 'A' then
if @FQA = 'Q' And @Moves < 4 And @Months < 16 And @Breed <> 'FR' And @Breed <> 'FRX' @Dest = 'SA'
When 'B'
etc etc etc
It doesent like the if statement
I am trying to set a flag based on the information passed to the store procedure
Think I am doing it too vb ish
Thanks
解决方案
Is this what you meant?
It assumes you are testing @sex = 'A' in addition to the other conditions.
I hope this helps.
Don
Alter ProCEDURE SD @Orderid int, @Scaleno int, @Sex Varchar(1), @Breed Varchar(3), @Moves int, @FQA varchar(1), @Months int AS Begin declare @Dest Varchar(3) if (@FQA = 'Q' And @Moves < 4 And @Months < 16 And @Breed <> 'FR' And @Breed <> 'FRX' and @Sex = 'A') begin set @Dest = 'SA' end end
/* exec SD 0, 0, 'A', 'BG', 2, 'Q', 10 exec SD 0, 0, 'B', 'BG', 2, 'Q', 10 exec SD 0, 0, 'A', 'BG', 4, 'Q', 10 */ create PROC spSD @Orderid int, @Scaleno int, @Sex Varchar(1), @Breed Varchar(3), @Moves int, @FQA varchar(1), @Months int AS Begin declare @Dest nvarchar(3) set @dest = case when @Sex = 'A' then case when @FQA = 'Q' And @Moves < 4 And @Months < 16 And @Breed <> 'FR' And @Breed <> 'FRX' then 'SA' else 'BL2' end else 'BLH' end select @Dest; end
这篇关于SQL存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文