日期:2014-05-17  浏览次数:20373 次

求大神指导一个批量插入的存储过程
小弟,想在新增学生的时候,插入这个学生在这个学期所要学习的内容的GUID 和初始化分数 但是不知道具体怎么写,我的思路是是使用 
insert into student_estimate_ships(GUID,FKstudentID,PKEstimateProjectID) select NEWID(),@studentid,PKEstimateProjectID from #table//@studentid 是传入存储过程的学生ID~我不知道这个参数怎么提前插入临时表
~~
临时表的创建 
create table #t ( studentid nvarchar(36),PKEstimateProjectID nvarchar(2000))

我的查询PKEstimateProjectID 语句是
  select d.PKEstimateProjectID
  from estimate_project d,(  select a.PKSemesterCourseID
  from semester_course_ships a ,(  select PKCourseID
  from estimate_course where FKClassTypeID ='85d75476-d5e3-420b-a7dc-112f6f470534') b
  where a.FKCourseID = b.PKCourseID) f where d.FKSemesterCourseID =f.PKSemesterCourseID order by FKAbilityProjectID --这里获取全部的PKEstimateProjectID 
不知道怎么吧这里的PKEstimateProjectID  和上面传入的参数@studentid插入临时表~~,最后再用上面的
insert into student_estimate_ships(GUID,FKstudentID,PKEstimateProjectID) select NEWID(),@studentid,PKEstimateProjectID from #table//@studentid 是传入存储过程的学生ID~我不知道这个参数怎么提前插入临时表 插入到student_estimate_ships表~~最后的50分 还望哪位大神~~指导下 有代码~最好~小弟愚钝~~·不知道如何下手~~~~

存储过程 批量插入 创建临时表

------解决方案--------------------
说的有点乱。而且中间那语句也不好,子查询里面带子查询
------解决方案--------------------
INSERT INTO student_estimate_ships([GUID],FKstudentID,PKEstimateProjectID) 
SELECT NEWID(),@studentid,d.PKEstimateProjectID 
FROM semester_course_ships a JOIN estimate_course b 
ON b. FKClassTypeID ='85d75476-d5e3-420b-a7dc-112f6f470534' AND a.FKCourseID = b.PKCourseID 
JOIN  estimate_project d 
ON d.FKSemesterCourseID =a.PKSemesterCourseID

------解决方案--------------------
引用:
你好,怎么插入临时表信息,一个是从SQL插入的信息 ,一个是C#后台传入的学生GUID~~怎么把这两个信息插入临时表?

不需要插入临时表,直接当成变量用就可以了。
------解决方案--------------------
最好把要处理数据库的一系列动作写成procedure,然后在c#调用。
在线指导:
http://item.taobao.com/item.htm?spm=686.1000925.1000774.23.nFGG8X&id=27406928729



------解决方案--------------------
这个临时表的用途还是不清楚。
如果你能把业务需求描述一下,可能会有更好的解决办法,甚至不需要临时表。