您的位置:首页 > 其它

返回自增Id,循环插入关联数据

2016-08-11 18:15 561 查看
declare @id int;

INSERT INTO Fotomall_Product_Category(categoryName, parentId, categoryNote,categoryLevel) values (@categoryName, @parentId,@categoryNote,@categoryLevel);
set @id= SCOPE_IDENTITY();

if(@id>0)
begin
declare  @i  int;
declare  @seprator  varchar(10);
declare  @propertyId  nvarchar(200);

set @seprator = ',';
set @propertyId = rtrim( ltrim( @propertyIds ))

set @i = charindex(@seprator, @propertyId)

while  @i  >=  1
BEGIN
INSERT INTO Fotomall_Product_CRelationP(categoryId,propertyId) VALUES(@id,left(@propertyId, @i - 1));

set @propertyId = substring(@propertyId, @i + 1, len(@propertyId)- @i)

set @i = charindex(@seprator, @propertyId)
END
if @inputstr <> ''
BEGIN
INSERT INTO Fotomall_Product_CRelationP(categoryId,propertyId) VALUES(@id,@propertyId);
END
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息