我有一个函数,如果表中有一行包含用户输入的值,则需要返回true。
我需要将值写入Ii返回的变量,但出现错误:
'@ ret'附近的语法不正确。
USE BDLab5;
GO
Create Function WasComplaint (@date date, @component varchar)
Returns BIT
Begin
Declare @was int, @ret bit
Select @was = ComponentCode from Complaints
Where ComplaintDate = @date AND
ComponentCode = (Select ComponentCode from Components Where ComponentName = @component)
if (@was = 0)
@ret = 0
else
@ret = 1
Return @ret
End;
我尝试了if else语法的其他变体,但没有帮助。
将值分配给变量时,需要使用SET
。
USE BDLab5;
GO
Create Function WasComplaint (@date date, @component varchar)
Returns BIT
Begin
Declare @was int, @ret bit
Select @was = ComponentCode from Complaints
Where ComplaintDate = @date AND
ComponentCode = (Select ComponentCode from Components Where ComponentName = @component)
if (@was = 0)
set @ret = 0
else
set @ret = 1
Return @ret
End;
[在给SET
值时将其放在@ret
之前