简体   繁体   English

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

[英]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'. 我试图采用函数给出的值并将其保存到变量中,以检查其是否不等于“ 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? 您不能直接在where子句中调用该函数吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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