简体   繁体   中英

Save the result of an SQL function to a variable within a select statement?

I am trying to take the value given by my function and save it to a variable for the purpose of checking that it is not = '0'. After extensive searching I cannot find a way to do this that works. Is it even possible?

DECLARE @InspectionID AS VARCHAR(10)
SELECT 
    SYEL.UserComments AS 'UserComments',
    SET @InspectionID = [Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)
FROM SY_Edit_Log SYEL
WHERE SYEL.UserCode = 'broberts'
AND @InspectionID <> '0'

Could you not call the function directly in the where clause?

SELECT 
    SYEL.UserComments AS 'UserComments',
FROM SY_Edit_Log SYEL
WHERE SYEL.UserCode = 'broberts'
AND [Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments) <> '0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM