最近一直在做Dnn模塊的開發
然後在存儲過程中用SubString配合CharIndex把分割開來
詳細的存儲過程
CREATE PROCEDURE dbo
@ProductId_Array varChar(
@ModuleId int
AS
DECLARE @PointerPrev int
DECLARE @PointerCurr int
DECLARE @TId int
Set @PointerPrev=
set @PointerCurr=
begin transaction
Set NoCount ON
delete from ProductListSpecial where ModuleId=@ModuleId
Set @PointerCurr=CharIndex(
set @TId=cast(SUBSTRING(@ProductId_Array
Insert into ProductListSpecial (ModuleId
SET @PointerPrev = @PointerCurr
while (@PointerPrev+
Begin
Set @PointerCurr=CharIndex(
if(@PointerCurr>
Begin
set @TId=cast(SUBSTRING(@ProductId_Array
Insert into ProductListSpecial (ModuleId
SET @PointerPrev = @PointerCurr
End
else
Break
End
set @TId=cast(SUBSTRING(@ProductId_Array
Insert into ProductListSpecial (ModuleId
Set NoCount OFF
if @@error=
begin
commit transaction
end
else
begin
rollback transaction
end
GO
網友Bizlogic對此的改進方法:
應該用SQL
CREATE Procedure [dbo]
(
@ProductId_Array NVARCHAR(
@ModuleId INT
)
AS
delete from ProductListSpecial where ModuleId=@ModuleId
IF (@ProductId_Array IS NULL OR LEN(LTRIM(RTRIM(@ProductId_Array))) =
RETURN
DECLARE @idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT
Insert into ProductListSpecial (ModuleId
Select
@ModuleId
FROM
OPENXML(@idoc
with (ProductId int ) as C
where
C
EXEC sp_xml_removedocument @idoc
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22113.html