我编写了一个存储过程,如下所示
Create table #Temp(
TLOAID int,
TLOAName nvarchar(50)
);
-- drop table #Temp;
DECLARE @string VARCHAR(max) = 'Casualty, Insurance, Debit,';
-- SET @string = @LOAStringParam;
SELECT B.LOAId AS TLOAID,
B.LOAName TLOAName
INTO #temp
FROM (SELECT Rtrim(Ltrim(Split.a.value('.', 'VARCHAR(100)'))) AS Data
FROM (SELECT Cast ('<M>' + Replace(@string, ',', '</M><M>') + '</M>' AS XML) AS Data) AS A
CROSS APPLY Data.nodes ('/M') AS Split(a)) a
JOIN tbLOA B
ON a.data = B.LOAName;
If(exists(SELECT tbPLOA.LOAId
FROM tbPLOA
WHERE tbPLOA.LOAId NOT IN(SELECT #Temp.TLOAID from #Temp) AND PId= @PId))
BEGIN
....
....
END
...
现在它正在抛出类似
的错误消息'a'附近的语法不正确。
我无法追踪此错误!请帮帮我!!!
答案 0 :(得分:0)
尝试像这样更改别名。
CREATE TABLE #Business
(BId INT,BName VARCHAR(50)
)
INSERT INTO #Business
VALUES (1,'Casualty'),(2,'Insurance'),(3,'Debit'),(4,'JKL')
DECLARE @strng VARCHAR(max) = 'Casualty, Insurance, Debit,'
SELECT B.BId AS TBIB,
B.BName TBName
INTO #temp
FROM (SELECT Rtrim(Ltrim(Split.sp.value('.', 'VARCHAR(100)'))) AS Data
FROM (SELECT Cast ('<M>' + Replace(@strng, ',', '</M><M>') + '</M>' AS XML) AS Data) A
CROSS APPLY Data.nodes ('/M') AS Split(sp)) oo
JOIN #Business B
ON oo.data = B.BName
SELECT *
FROM #temp