SQL Server 常用日期查询语句】的更多相关文章

--本月月初select  dateadd(mm,datediff(mm,0,getdate()),0) --本月月末select  DATEADD(DD,-1,DATEADD(MONTH,1+DATEDIFF(MONTH,0,GETDATE()),0))--设置每周的第一天为星期一SET  DateFirst 1declare @cur_week1 varchar(10)--本周第一天select @cur_week1=DATEADD(DAY,1-DATEPART(WEEKDAY,getdat…
最近在加强sql 语句的学习,整理一下基本语法,现在记录下 select * from dbo.cangku where city='河南' select  distinct(city), cangkuId from dbo.cangku    //取消重复的列值 select  SUM (gongzi) as  zgz  from dbo.zhigong    //总工资 select cangkuId ,city  from dbo.cangku   where not city='河南'…
基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; --top 取…
假设当前是第PageNo页,每页有PageSize条记录,现在分别用Mysql.Oracle和SQL Server分页查询student表. 1.Mysql的分页查询: SELECT * FROM student LIMIT (PageNo ) * PageSize,PageSize; 理解:(Limit n,m)  =>从第n行开始取m条记录,n从0开始算. 2.Oracel的分页查询: SELECT * FROM ( SELECT ROWNUM rn ,* FROM student WHER…
SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 例如: select getdate() 2004-09-12 11:06:08.177 整理了一下SQL Server里面可能经常会用到的日期格式转换方法: 举例如下: select CONVERT(varchar, getdate(), 120 ) 2004-09-12 11:06:08 select replace(replace(replace(CONVERT(varchar…
1.如果查询日期参数为'2017/02/21',而数据库表中的字段为'2017/02/21 12:34:16.963',则需要格式化一下日期才能查询出来,如下 select * from table t where t.date between CONVERT(datetime, '2017/02/21', 120) and CONVERT(datetime, '2017/02/21', 120)+' 23:59:59') ; 查询的范围为'2017/02/21 00:00:00'~'2017/…
https://msdn.microsoft.com/en-us/library/ms175081.aspx…
-- Get childs by parent id WITH Tree AS ( SELECT Id,ParentId FROM dbo.Node P WHERE P.Id = -- parent id UNION ALL SELECT C.Id,C.ParentId FROM dbo.Node C INNER JOIN Tree T ON C.ParentId = T.Id ) SELECT * FROM Tree -- Get parents by child id WITH Tree A…
/*8 24 108 - hh:mm:ss */ Select CONVERT(varchar(), GETDATE(), )-- :: Select CONVERT(varchar(), GETDATE(), )-- :: Select CONVERT(varchar(), GETDATE(), )-- :: /*11 - yy/mm/dd */ Select CONVERT(varchar(), GETDATE(), )-- // /*111 - yyyy/mm/dd */ Select C…
-- 根据父ID得到所有子ID -- Get childs by parent idWITH TreeAS( SELECT Id,ParentId FROM dbo.Node P WHERE P.Id = 21 -- parent id,即父记录 UNION ALL SELECT C.Id,C.ParentId FROM dbo.Node C INNER JOIN Tree T ON C.ParentId = T.Id                           -- 所有子记录) SE…