到刪除的記錄我有一個存儲過程中進行的插入記錄,但以逗號分隔的字符串,分析它,並加入個人記錄如何使用IN子句
Create PROCEDURE [dbo].[Save_List_PMIDS]
@MemberID INT= 88888,
@PMIDList VARCHAR(MAX)= '12345,56789,67432'
AS
BEGIN
SELECT Split.a.value('.', 'VARCHAR(100)') AS PMID
INTO #pmids
FROM (SELECT CAST ('<M>' + REPLACE(@PMIDList, ',', '</M><M>') + '</M>' AS XML) AS String
) AS A
CROSS APPLY String.nodes('/M') AS Split (a)
--DELETE FROM [dbo].[Publication.Person.Include]
--WHERE (MemberID = @MemberID) AND PMID IN (@PMIDList);
INSERT INTO [dbo].[Publication.Person.Include]
(PersonID, PMID, MemberID)
SELECT @MemberID, PMID, @MemberID
FROM #pmids
DROP TABLE #pmids
我的問題是與delete語句。如何將PMIDList字符串轉換爲IN列表中要使用的數字,以便我不添加重複項?
因此,它看起來像
DELETE FROM [dbo].[Publication.Person.Include]
WHERE (MemberID = @MemberID) AND PMID IN (12345,56789,67432);
在此先感謝
[傳遞一個varchar全逗號分隔值到SQL Server IN功能]的可能的複製(http://stackoverflow.com/questions/878833/passing -a-varchar-full-of-comma-delimited-values-to-a-sql-server-in-function) – AndreFeijo
http://stackoverflow.com/a/10333589/630284 – SQLMason
可能的重複[SQL in(@變量)查詢](http://stackoverflow.com/questions/10333319/sql-in-variable-query) – SQLMason