我在建一个存储过程的时候要涉及到根据参数的值来判断要怎么执行,在一般的语言中都有IF语句,那么在SQL中有类似的吗?请各位高手指点一下!例:
create proc aaa(@ad int)
as
下面是如果@ad为0则执行一组语句
如果@ad为1的话又执行一组语句,在SQL中要怎么来写?
create proc aaa(@ad int)
as
下面是如果@ad为0则执行一组语句
如果@ad为1的话又执行一组语句,在SQL中要怎么来写?
BEGIN
...
END
beginend
elseif @ad=1
beginend
beginend
elseif @ad=1
beginend
beginend
elseif @ad=1
beginend
IF...ELSE (Transact-SQL) IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ] Examples
DECLARE @compareprice money, @cost money
EXECUTE usp_GetList '%Bikes%', 700,
@compareprice OUT,
@cost OUTPUT
IF @cost <= @compareprice
BEGIN
PRINT 'These products can be purchased for less than
$'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'
END
ELSE
PRINT 'The prices for all products in this category exceed
$'+ RTRIM(CAST(@compareprice AS varchar(20)))+'.'
begin
...
end