1 use StudentManageDB 2 go 3 --定义变量并查询 4 declare @sumScore int 5 select @sumScore=(CSharp+SQLServerDB) from ScoreList 6 where StudentId=100003 7 --输出 8 --print '学号=100003总成绩:'+@sumScore 9 10 print '学号=100003总成绩:'+convert(varchar(20),@sumScore)
1 use StudentManageDB2 go3 --使用CAST转换4 select StudentName + '的出生日期是:' + CAST(Birthday as varchar(50)) AS '学生信息'5 from Students where StudentId=1000056 --使用CONVERT转换7 select StudentName + '的出生日期是:' + CONVERT(varchar(50),Birthday,102) AS '学生信息'8 from Students where StudentId=100005
1 use StudentManageDB 2 go 3 --定义变量 4 declare @birthday datetime,@days int,@age int 5 --查询出生日期 6 select @birthday=Birthday from Students where StudentId=100002 7 --计算出生天数 8 set @days=datediff(dayofyear,@birthday,getdate()) 9 --计算年龄10 set @age=floor(@days/365)11 --输出信息12 print '100002学员年龄:'+convert(varchar(20),@age)13 14 --直接查询15 select FLOOR(DATEDIFF(dy, Birthday, GETDATE())/365) 年龄16 from Students where StudentId=100002