码迷,mamicode.com
首页 > 数据库 > 详细

sql 将查询的结果集一次性插入到表变量中

时间:2016-09-21 11:34:32      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

declare @Subject table
(--题目表变量
    SubjectID int,
    Question nvarchar(MAX),
    CorrectAnswer varchar(100),
    Explain nvarchar(MAX),
    SubjectTypeID int,
    CreateID int,
    CreateDate datetime,
    SubjectScore decimal(3, 1),
    ScoreSort int
)
insert into @Subject(SubjectID,Question,CorrectAnswer,Explain,SubjectTypeID,CreateID,CreateDate,SubjectScore,ScoreSort)
select a.SubjectID,a.Question,a.CorrectAnswer,a.Explain,a.SubjectTypeID,a.CreateID,a.CreateDate,a.SubjectScore,a.ScoreSort from
    (--题目表(传入参数 HistPaperID,subjecttitleid)
    select a.SubjectID,Question,Answer as CorrectAnswer,Explain,TypeID as SubjectTypeID,a.CreateID,CreateDate,Score as SubjectScore,Sort as ScoreSort from HistPaperSubject a
    left join HistPaperSubjectScore b on a.subjectID=b.subjectID
    where a.isdel=0 and a.HistPaperID=60 and b.HistPaperID=60 and b.subjecttitleid=193) a
select * from     @Subject

 

sql 将查询的结果集一次性插入到表变量中

标签:

原文地址:http://www.cnblogs.com/zhyue93/p/sql_1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!