我有以下从视图调用的 SQL 函数
ALTER FUNCTION [dbo].[GetModulesforTesCaseID]
(@TestCaseID numeric(18))
RETURNS VARCHAR(1000)
AS
BEGIN
declare @Modules VARCHAR(1000)
select @Modules = SUBSTRING(
(SELECT ',' + cast (S.MODULENAME as varchar)
FROM MODULE s JOIN EFFMODFORTESTCASE EMTC ON S.MODULEID = EMTC.MODULEID
JOIN TESTCASE TC ON TC.TESTCASEID = EMTC.TESTCASEID
where tc.testcaseid = @TestCaseID
ORDER BY s.MODULENAME
FOR XML PATH('')),2,200000)
if @Modules is null BEGIN
set @Modules = SELECT M.MODULENAME FROM MODULE M JOIN SUBMODULESFORMODULE SFM ON SFM.MODULEID = M.MODULEID
JOIN EFFSUBMODFORTESTCASE ESMTC ON ESMTC.SUBMODULEID = SFM.SUBMODULEID WHERE TESTCASEID = @TestCaseID
END
return @Modules
end
我正进入(状态
消息 156,级别 15,状态 1,过程 GetModulesforTesCaseID,第 16 行
关键字“SELECT”附近的语法不正确
请帮助我纠正 If 条件下的语法错误