I’ve created a sproc to delete multiple records by accepting a comma-delimited list of ID’s as varchar, and using IN to attempt the deletion – doesn’t work:
ALTER PROCEDURE [dbo].[sp_DeleteItemsFromItemCategories]
@UserID bigint,
@ItemsList varchar(8000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE
FROM tbl_ItemFoldersLnk
WHERE LineItemID IN (SELECT LineItemID FROM tbl_ItemFoldersLnk WHERE LineItemID IN (@ItemsList))
END
Initially I had … IN (@ItemList) but still does not work. The error is “Error converting data type varchar to bigint.”
I do have other SPROCS that iterate through comma delimited lists which I could use to delete, but then I’m running a delete function for each row.
Suggestions?
Thanks.
Arrays and lists in SQL Server.
You need to change the CSV into a table (as per article) and join to filter.
You are literally comparing the ID columns with the string “1, 45, 67” which is not an integer…