declare @a varchar(10),@b int,@c varchar(10)
select @a='SQL Server',@b=2019,@c='Developer'
print @a+' '+cast(@b as varchar(4))+' '+@c
declare @num int,@tdept varchar(10)
set @num=(select top 1 count(*)from teacher group by Tdept order by count(*) desc)
set @tdept=(select top 1 Tdept from teacher group by Tdept order by count(*) desc)
print @tdept+' 人数最多,共有'+cast(@num as varchar(4))+'人'
declare @avg_grade numeric(4,1)
select @avg_grade=avg(grade) from sc where cno='201'
if @avg_grade>80
print'高等数学课程的平均分超过了80分'
else
print'高等数学课程的平均分没有超过80分'
declare @i int,@sum int
select @i=0,@sum=0
while @i >=0
begin
set @i=@i+1
if @i>100
begin
select '0~100的偶数和为 '=@sum
break
end
if(@i%2)!=0
continue
else
SELECT @sum=@sum+@i
end
print @sum
select sno 学号,cno 课程号,grade 成绩,成绩等级=
case
when grade >=90
then '优秀'
when grade >=80
then '良好'
when grade >=70
then '中等'
when grade >=60
then '及格'
WHEN grade < 60 THEN '不及格'
ELSE '不合法'
end
from sc
declare @sum int
select @sum=COUNT(*) from SC where Cno='301'
IF @sum>0
PRINT '有“信息系统”课程的选课记录'
ELSE
PRINT '没有查询到“信息系统”课程的选课记录'
select floor(-1.23)
select 14+rand()*4
SELECT FLOOR(14+RAND()*5)
select cno 课程编号,cname 课程名称,len(cname),DATALENGTH(cname)
from course
where Cname LIKE '%C%'
select charindex('bar','foobarbar')
select right('foobarbar',5)
'www.mysql.com'
select replace('www.mysql.com','mysql','sqlserver')
select month(getdate())
SELECT DATEADD(DY,100,GETDATE())
SELECT DATEADD(Y,100,GETDATE())
SELECT DATEADD(D,100,GETDATE())
SELECT DATEADD(DD,100,GETDATE())
select DB_NAME()