怎么用sql语句循环添加数据?
--保存分类权限ALTERPROC[dbo].[CH_FRM_DeleteAndInsertCategoryAuthorityInfo](@Idvarchar(36),@...
--保存分类权限
ALTER PROC [dbo].[CH_FRM_DeleteAndInsertCategoryAuthorityInfo]
(
@Id varchar(36),
@CategoryId varchar(36),
@RoleOrUserId varchar(36),
@LastUpdateUserId varchar(36)
)
as
begin
BEGIN tran TranStart
SAVE tran FirstPoint
DELETE FROM dbo.CH_FRM_CategoryAuthority WHERE RoleOrUserId=@RoleOrUserId
--在这个地方需要循环添加数据
Insert into dbo.CH_FRM_CategoryAuthority(Id, CategoryId, RoleOrUserId, LastUpdateUserId)
values(@Id,@CategoryId,@RoleOrUserId,@LastUpdateUserId)
COMMIT TRANSACTION TranStart
if @@ERROR <> 0
begin
rollback tran FirstPoint
end
else
begin
commit tran TranStart
END
END 展开
ALTER PROC [dbo].[CH_FRM_DeleteAndInsertCategoryAuthorityInfo]
(
@Id varchar(36),
@CategoryId varchar(36),
@RoleOrUserId varchar(36),
@LastUpdateUserId varchar(36)
)
as
begin
BEGIN tran TranStart
SAVE tran FirstPoint
DELETE FROM dbo.CH_FRM_CategoryAuthority WHERE RoleOrUserId=@RoleOrUserId
--在这个地方需要循环添加数据
Insert into dbo.CH_FRM_CategoryAuthority(Id, CategoryId, RoleOrUserId, LastUpdateUserId)
values(@Id,@CategoryId,@RoleOrUserId,@LastUpdateUserId)
COMMIT TRANSACTION TranStart
if @@ERROR <> 0
begin
rollback tran FirstPoint
end
else
begin
commit tran TranStart
END
END 展开
3个回答
展开全部
for循环
例如:for(int i=0;i<5;i++){ //5为你需要的循环数组 比如权限
Insert into dbo.CH_FRM_CategoryAuthority(Id, CategoryId, RoleOrUserId, LastUpdateUserId)
values(@Id,@CategoryId,@RoleOrUserId,@LastUpdateUserId)
}
例如:for(int i=0;i<5;i++){ //5为你需要的循环数组 比如权限
Insert into dbo.CH_FRM_CategoryAuthority(Id, CategoryId, RoleOrUserId, LastUpdateUserId)
values(@Id,@CategoryId,@RoleOrUserId,@LastUpdateUserId)
}
追问
大哥 我不知道有几条信息啊 是动态的
追答
放到list里循环取出来
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
;//将数组组成字符串 ,分隔符为','
$ele="'".$ele."'";这样$ele就像是‘a’,'b','c'的形式了,然后组合进insert语句就可以了
$ele="'".$ele."'";这样$ele就像是‘a’,'b','c'的形式了,然后组合进insert语句就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询