SET@date1=GETDATE(); SET@date2=CONCAT((Select CurrentAcademicYear from SchoolDataManagement),'-09-01'); SET@date3=CONCAT(((Select CurrentAcademicYear from SchoolDataManagement)+1),'-03-01'); SET@date4=CONCAT(((Select CurrentAcademicYear from SchoolDataManagement)+1),'-08-01');
IF @date1=@date2 SELECT'第一学期'as SemesterName ELSE IF @date1>@date2AND@date1<@date3 SELECT'第一学期'as SemesterName ELSE IF @date1>@date3AND@date1<@date4 SELECT'第二学期'as SemesterName;
如果你SELECT ‘第一学期’ 即可发现,’第一学期’会变成????问号
解决办法
在冒号前添加N即可
1 2 3
SELECT* FROM [DataManagement].[PersonalDetails] where ChineseName = N'成龙'
SET@date1=GETDATE(); SET@date2=CONCAT((Select CurrentAcademicYear from SchoolDataManagement),'-09-01'); SET@date3=CONCAT(((Select CurrentAcademicYear from SchoolDataManagement)+1),'-03-01'); SET@date4=CONCAT(((Select CurrentAcademicYear from SchoolDataManagement)+1),'-08-01');
IF @date1=@date2 SELECT N'第一学期'as SemesterName ELSE IF @date1>@date2AND@date1<@date3 SELECT N'第一学期'as SemesterName ELSE IF @date1>@date3AND@date1<@date4 SELECT N'第二学期'as SemesterName;