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

是否将SQL函数的结果保存到select语句中的变量?,sql,sql-server,Sql,Sql Server,我试图获取函数给定的值并将其保存到变量中,以检查它是否为='0'。经过广泛的搜索,我找不到一种可行的方法。有可能吗 DECLARE @InspectionID AS VARCHAR(10) SELECT SYEL.UserComments AS 'UserComments', SET @InspectionID = [Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments) FROM SY_E

我试图获取函数给定的值并将其保存到变量中,以检查它是否为='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'
将@InspectionID声明为VARCHAR(10)
挑选
SYEL.UserComments作为“UserComments”,
SET@InspectionID=[Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)
从SY_编辑SYEL日志
其中SYEL.UserCode='broberts'
和@InspectionID“0”

您不能在where子句中直接调用函数吗

SELECT 
    SYEL.UserComments AS 'UserComments',
FROM SY_Edit_Log SYEL
WHERE SYEL.UserCode = 'broberts'
AND [Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments) <> '0'
选择
SYEL.UserComments作为“UserComments”,
从SY_编辑SYEL日志
其中SYEL.UserCode='broberts'
和[Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)“0”

您不能在where子句中直接调用函数吗

SELECT 
    SYEL.UserComments AS 'UserComments',
FROM SY_Edit_Log SYEL
WHERE SYEL.UserCode = 'broberts'
AND [Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments) <> '0'
选择
SYEL.UserComments作为“UserComments”,
从SY_编辑SYEL日志
其中SYEL.UserCode='broberts'
和[Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)“0”

我不熟悉在SQL Server中使用函数,只是简单地说了一下:你能在[Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)'0'?如果可能的话,我会将你的标量函数改为内联表值函数。你将从中获得一些重要的性能提升。我甚至不确定这是什么,但我肯定会研究它。谢谢你,肖恩!发布你的标量函数,我会看看我们是否可以为你转换它。我不熟悉SQL Server中的函数,只是把它扔了出去:你能在[Silco_Final].[dbo].[GetInspectionIDFromUserComments](SYEL.UserComments)中使用
吗“0”
?如果可能,我会将标量函数改为内联表值函数。你将从中获得一些重要的性能提升。我甚至不确定这是什么,但我肯定会研究它。谢谢你,肖恩!发布你的标量函数,我会看看我们是否能为你转换它。伙计,我从来没有想过。。。太棒了!老兄,我从没想过。。。太棒了!