setANSI_NULLSONsetQUOTED_IDENTIFIERONgoALTERPROCEDURE[dbo].[TeacherSchedule]@Teache
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[TeacherSchedule]
@TeacherId int,
@CourseType nvarchar(200),
@Begin datetime,
@End datetime
AS
declare @KpjsScheduleDateTime datetime,@KpjsTimeId int;
declare @datetime datetime, @week nvarchar(250), @classtime nvarchar(250), @Kpjs nvarchar(250), @KpjsAssistant int, @KpjsCourse nvarchar(250), @KpjsClass nvarchar(250), @SubjectNote nvarchar(250), @hours decimal(18,2),@TeacherHours decimal(18,2), @LessonPlanId int, @LessonPlanLength bigint, @TeachingLogLength bigint, @XiaoQu nvarchar(250);
declare @IsSuccess int ,@IsSuccessReason nvarchar(50);
declare @RestTime nvarchar(250);
declare @HeGeYesOrNo nvarchar(250),@HeGeUserName nvarchar(250);
declare @i int ; set @i = 0;
declare @KpjsLessonPlanLength_KpjsScheduleId bigint;
--tableSchedule
create table #ts (
[datetime] datetime null,
[week] nvarchar(250) null,
[time] nvarchar(250) null,
[TimeId] int null,
[CourseType] nvarchar(250) null,
[KpjsAssistant] int null,
[OneToOneStudentNo] int null,
[IsSuccess] int null,
[IsSuccessReason] nvarchar(250) null,
[course] nvarchar(250) null,
[class] nvarchar(250) null,
[XiaoQu] nvarchar(250) null,
[subjectnote] nvarchar(250) null,
[LessonPlanId] int null,--Kpjs , Nhw, Ielts, OneToOne
[LessonPlanLength] bigint null,
[TeachingLogLength] bigint null,
[CourseType2] nvarchar(250) null,
[course2] nvarchar(250) null,
[class2] nvarchar(250) null,
[subjectnote2] nvarchar(250) null,
[CourseType3] nvarchar(250) null,
[course3] nvarchar(250) null,
[class3] nvarchar(250) null,
[subjectnote3] nvarchar(250) null,
[CourseType4] nvarchar(250) null,
[course4] nvarchar(250) null,
[class4] nvarchar(250) null,
[subjectnote4] nvarchar(250) null,
[hours] decimal(18,2),
[TeacherHours] decimal(18,2),
[HeGeYesOrNo] nvarchar(250),
[HeGeUserName] nvarchar(250),
[RestTime] nvarchar(255)
)
if @CourseType = 'Kpjs' or @CourseType = 'All'
BEGIN
--Kpjs
declare DistinctDateTime cursor for
select distinct KpjsScheduleDateTime,KpjsTimeId from KpjsSchedule where (TeacherId = @TeacherId or AssistantId = @TeacherId ) and KpjsScheduleDateTime >= @Begin and KpjsScheduleDateTime <=@End
open DistinctDateTime
FETCH NEXT from DistinctDateTime into @KpjsScheduleDateTime,@KpjsTimeId
while @@FETCH_STATUS = 0
BEGIN
--insert into #ts ([datetime],[time],[hours]) values (@KpjsScheduleDateTime,(select t.KpjsTimeBeginHour + ':' + t.KpjsTimeBeginMinute +'-'+t.KpjsTimeEndHour+':'+t.KpjsTimeEndMinute as classtime from KpjsTime t where KpjsTimeId = @KpjsTimeId), (select (CONVERT(decimal(18,2),t.KpjsTimeEndHour) - CONVERT(decimal(18,2),t.KpjsTimeBeginHour)) + convert(decimal(18,2), (convert(decimal(18,2),t.KpjsTimeEndMinute) - convert(decimal(18,2),t.KpjsTimeBeginMinute))/60 ) from KpjsTime t where KpjsTimeId = @KpjsTimeId));
declare kpjsSchedule cursor for
select convert(nvarchar(10),s.KpjsScheduleDateTime,20) as [datetime]
,s.KpjsScheduleWeek
,t.KpjsTimeBeginHour + ':' + t.KpjsTimeBeginMinute +'-'+t.KpjsTimeEndHour+':'+t.KpjsTimeEndMinute as classtime
,s.KPJS
,case s.AssistantId when @TeacherId then 1 else 0 end as KpjsAssistant
,course.KpjsCourse
,KpjsClass.KpjsClass + '(' +KpjsClass.KpjsClassStudyType + ')' as KpjsClass
,KpjsClass.XiaoQu
,s.SubjectNote + CASE WHEN LEN(s.SpeakingTopic) > 0 THEN '-'+s.SpeakingTopic ELSE '' END
, (CONVERT(decimal(18,2),t.KpjsTimeEndHour) - CONVERT(decimal(18,2),t.KpjsTimeBeginHour)) + convert(decimal(18,2), (convert(decimal(18,2),t.KpjsTimeEndMinute) - convert(decimal(18,2),t.KpjsTimeBeginMinute))/60 ) as hours
,s.TeacherHours
,s.IsSuccess
,s.IsSuccessReason
,KpjsLessonPlan.KpjsLessonPlanHeGeOrNoHeGe as HeGeYesOrNo
,KpjsLessonPlan.KpjsLessonPlanHegeUserName as HeGeUserName
,KpjsLessonPlan.KpjsLessonPlanId as LessonPlanId
,s.KpjsScheduleId as LessonPlanLength , ---用于到KpjsLessonPlanLength 再次查看lesson plan长度
DATALENGTH(KpjsLessonPlan.ClassRoom)+DATALENGTH(convert(nvarchar(100),KpjsLessonPlan.StudentNumber))+DATALENGTH(KpjsLessonPlan.SummaryAfterClass) as TeachingLogLength ,
CASE
WHEN RestTimeFrom != '' THEN RestTimeFrom + '-' + RestTimeTo + '
'
ELSE ' '
END
+
CASE
WHEN RestTimeFrom2 != '' THEN RestTimeFrom2 + '-' + RestTimeTo2 + '
'
ELSE ' '
END
+
CASE
WHEN RestTimeFrom3 != '' THEN RestTimeFrom3 + '-' + RestTimeTo3
ELSE ' '
END
AS RestTime
from KpjsSchedule s inner join KpjsTime t on s.KpjsTimeId = t.KpjsTimeId
inner join KpjsCourse course on s.KpjsCourseId = course.KpjsCourseId
inner join KpjsClass on KpjsClass.KpjsClassId = s.KpjsClassId
left join KpjsLessonPlan on KpjsLessonPlan.KpjsScheduleId = s.KpjsScheduleId
where (s.TeacherId = @TeacherId or s.AssistantId = @TeacherId ) and s.KpjsScheduleDateTime = @KpjsScheduleDateTime and s.KpjsTimeId = @KpjsTimeId;
open kpjsSchedule
set @i =0;
fetch next from kpjsSchedule into @datetime,@week,@classtime,@Kpjs,@KpjsAssistant,@KpjsCourse,@KpjsClass,@XiaoQu,@SubjectNote,@hours,@TeacherHours,@IsSuccess,@IsSuccessReason,@LessonPlanId,@KpjsLessonPlanLength_KpjsScheduleId, @TeachingLogLength, @RestTime,@HeGeYesOrNo,@HeGeUserName;
while @@FETCH_STATUS = 0
BEGIN
set @i = @i+1;
if @i = 1
begin
EXEC [KpjsLessonPlanLength] @KpjsLessonPlanLength_KpjsScheduleId, @LessonPlanId OUTPUT , @LessonPlanLength OUTPUT , @TeachingLogLength OUTPUT ;
insert into #ts([datetime],[week],[time],[TimeId],[CourseType],[KpjsAssistant],[course],[class],[XiaoQu],[subjectnote],[LessonPlanId],[LessonPlanLength],[TeachingLogLength],[hours],[TeacherHours],[IsSuccess],[IsSuccessReason],[RestTime],[HeGeYesOrNo],[HeGeUserName])
values(@datetime,@week,@classtime,@KpjsTimeId,@Kpjs,@KpjsAssistant,@KpjsCourse,@KpjsClass,@XiaoQu,@SubjectNote,@LessonPlanId,@LessonPlanLength,@TeachingLogLength,@hours,@TeacherHours,@IsSuccess,@IsSuccessReason,@RestTime,Cast(@HeGeYesOrNo as nvarchar(250)),@HeGeUserName);
end
else
begin
if @i = 2
update #ts set [CourseType2]=@Kpjs,[course2]=@KpjsCourse,[class2]=@KpjsClass,[subjectnote2]=@SubjectNote where [datetime]=@datetime and [week] = @week and [time] = @classtime;
if @i = 3
update #ts set [CourseType3]=@Kpjs,[course3]=@KpjsCourse,[class3]=@KpjsClass,[subjectnote3]=@SubjectNote where [datetime]=@datetime and [week] = @week and [time] = @classtime;
if @i = 4
update #ts set [CourseType4]=@Kpjs,[course4]=@KpjsCourse,[class4]=@KpjsClass,[subjectnote4]=@SubjectNote where [datetime]=@datetime and [week] = @week and [time] = @classtime;
end
fetch next from kpjsSchedule into @datetime,@week,@classtime,@Kpjs,@KpjsAssistant,@KpjsCourse,@KpjsClass,@XiaoQu,@SubjectNote,@hours,@TeacherHours,@IsSuccess,@IsSuccessReason,@LessonPlanId,@KpjsLessonPlanLength_KpjsScheduleId, @TeachingLogLength,@RestTime;
end;
close kpjsSchedule;
deallocate kpjsSchedule;
FETCH NEXT from DistinctDateTime into @KpjsScheduleDateTime,@KpjsTimeId
End
CLOSE DistinctDateTime
DEALLOCATE DistinctDateTime
END
select convert(nvarchar(10),[datetime],20) as [datetime],
[week],
[time],
[TimeId],
[CourseType],
[KpjsAssistant],
[OneToOneStudentNo],
[IsSuccess],
[IsSuccessReason],
[course],
[class],
[XiaoQu],
[subjectnote],
[LessonPlanId],
[LessonPlanLength],
[TeachingLogLength],
[CourseType2],
[course2],
[class2],
[subjectnote2],
[CourseType3],
[course3],
[class3],
[subjectnote3],
[CourseType4],
[course4],
[class4],
[subjectnote4] ,
[hours],
[TeacherHours],
[RestTime] ,
[HeGeYesOrNo],
[HeGeUserName],
@TeacherId as TeacherId
from #ts order by [datetime], [time];
drop table #ts;
4 个解决方案
提示你的还不够啊,你把中文转成int,能行吗,哪个变量传递的是中文,搜一下,看看哪里对它进行转换了
将你原先保存了合格的int类型的列修改成varchar类型