返回自增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
相关文章推荐
- 创建存储过程向表中循环添加数据
- Mybatis实现insert获取自增id
- Entity Framework添加记录时获取自增ID值
- JDBC读取新插入Oracle数据库Sequence值的5种方法
- MySql存储过程使用游标循环插入数据示例
- js 去除空格
- 理解SQL Server是如何执行查询的 (2/3)
- RoR利用RSpec测试项目
- HDU 5831 Rikka with Parenthesis II (栈&思维)
- Android SDK中的自动化测试
- 可变字典(NSDictionary)与不可变字典(NSMutableDictionary)
- [唐诗]181玉阶怨-李白
- 使用 py.test 对 python 代码进行测试
- 静态库与动态库链接、执行时的搜索路径顺序
- 【Vijos-P1172】反质数-DFS
- css3笔记
- Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' ha
- Linux添加/删除用户和用户组
- Garbage Collectors
- c# 对excel数据进行打印