首页 > 代码库 > sql 将查询的结果集一次性插入到表变量中

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

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) aselect * from     @Subject

 

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