At the end of my function, I have a statement:
RETURN @Result
I want to do something like this:
IF (@Result = '') BEGIN @Result = 'Unknown' END RETURN @Result
The above doesn't work.
SET @Result = 'Unknown'
;)
IF (@Result = '') BEGIN SELECT @Result = 'Unknown' END RETURN @Result
Note that the assignment method in T-SQL is operator SELECT . You can also use the operator SET , although this is not recommended.
SELECT
SET
change this line
@Result = 'Unknown'
to
set @Result = 'Unknown'
I think you need to check if @result is NULL because NULL is not the same as ''
IF (ISNULL(@Result, '') = '') BEGIN SET @Result = 'Unknown' END RETURN @Result
IF (@Result = '')
TO BEGIN
END
@Justice: According to Microsoft - MSDN SELECT @Result = 'Unknown' is not recommended at all
SELECT @Result = 'Unknown'