将SQL函数的结果保存到select语句中的变量?

时间:2017-10-12 16:35:36

标签: sql sql-server

我试图获取我的函数给出的值并将其保存到变量中,以便检查它不是='0'。经过广泛的搜索后,我无法找到一种有效的方法。它甚至可能吗?

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'

1 个答案:

答案 0 :(得分:3)

你能否直接在where子句中调用该函数?

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