1.使用if else语句 ①在学生表中,查找名字为王刚的同学,如果存在,显示该同学的信息,否则显示查无此人 if exists(select sno from student where sname='王刚') else print '查无此人' go ②查看有无选修00008号课程的记录,如果有,则显示有,并查询选修00008号课程的人数 if exists(select * from sc where cno='00008') begin print '有' select cno,coun
--SQL查询优化 尽量避免使用or,not,distinct运算符,简化连接条件 /*Or运算符*/ use db_business go select * from 仓库 where 城市='北京' or 城市='青岛' --包含or运算符 sql将不使用索引,影响速度 /*In运算符*/ use db_business go select * from 仓库 where 城市 in('北京' ,'青岛') --有效提高运算效率 /*not运算符*/ use db_business go s
本文主要向大家介绍了SQLServer数据库之SQL Server 获取本周,本月,本年等时间内记录,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助. datediff(week,zy_time,getdate())=0 //查询本周datediff(month,zy_time,getdate())=0 //查询本月本季:select * from table where datediff(qq,C_CALLTIME,getdate())=0前半年1-6,后半年7-12