我的 SQL Server 2008 R2 数据库中有以下存储过程
ALTER PROCEDURE [dbo].[usp_send_email]
@pStatus Int Out,
@pEMailId Int Out,
@pSenderUserName varchar(MAX),
@pReceivers VarChar(50), **-- this column can have csv values**
@pSub NVarChar(100),
@pCon NVarchar(MAX),
@pHasAttachments Bit
AS
BEGIN
--SET NOCOUNT ON;
Insert Into MessagingMessage
(
CreatedBy,
[Subject],
Body,
HasAttachments
)
Values
(
@pSenderUserName,
@pSub,
@pCon,
@pHasAttachments
)
SET @pEMailId = SCOPE_IDENTITY()
Insert Into MessagingMessageReceipient
(
MessageId,
ReceipientId,
ReceipientType
)
Values
(
@pEMailId,
@pReceivers,
1
)
SET @pStatus = SCOPE_IDENTITY()
END
在上面的代码中,我只想运行第一个语句一次,但第二个插入语句循环中每个逗号分隔的 username.CSV 值作为参数已经通过 C# 代码验证,因此无需验证它。