首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

多条信息插入的存储过程

2012-05-28 
求一个多条信息插入的存储过程现在有老师表t,学生表s,排课信息表c,及考勤表k。现在传入的参数有老师名:teac

求一个多条信息插入的存储过程
现在有老师表t,学生表s,排课信息表c,及考勤表k。
现在传入的参数有老师名:teachername,学生名stuname,学生名是一个字符串如:张三,李四,王五 还有个状态参数state,
思路也很清楚:
  根据老师名取得老师id,再根据老师id从排课表中取得班级id,然后分离学生字符串把学生一个个插入到考勤表,
考勤表只有三个字段学生名跟state,班级id.

SQL语句会写,但是存储过程不会写,哪位大侠能帮忙下
 

[解决办法]

SQL code
if OBJECT_ID('pro_test')is not nulldrop proc pro_testgocreate proc pro_test (@teachername varchar(10),@stuname varchar(50),@state bit)asbegin--创建临时表存储你传进来的数据if OBJECT_ID('temp..#test')is not nulldrop table #testcreate table #test(teachername varchar(10),stuname varchar(50),[state] bit)--插入数据insert #testselect @teachername,@stuname,@state--将你传来的数据进行以下查询处理后在插入考勤表insert 考勤表select A.teachername, B.stuname,A.[state] from(     select teachername,stuname=convert(xml,' <root> <v>' +     replace(stuname, ',', ' </v> <v>') + ' </v> </root>'),[state]from #test)A outer apply(     select stuname = N.v.value('.', 'varchar(100)')    from A.stuname.nodes('/root/v') N(v) )B end 

热点排行