这两个语句统计出来的结果为什么不一样??
select * from aa
where convert(varchar(50),bb_time,120) > = '2007-09-29' and convert(varchar(50),bb_time,120) < = '2007-10-29';select * from aa
where convert(varchar(10),jf_time,120) > = '2007-09-29' and convert(varchar(10),jf_time,120) < = '2007-10-29';下面这两个语句却一样啊?
select * from aa
where convert(varchar(50),bb_time,112) > = '2007-09-29' and convert(varchar(50),bb_time,112) < = '2007-10-29';select * from aa
where convert(varchar(10),bb_time,112) > = '2007-09-29' and convert(varchar(50),bb_time,112) < = '2007-10-29';
与convert()的参数到底怎么用??
select * from aa
where convert(varchar(50),bb_time,120) > = '2007-09-29' and convert(varchar(50),bb_time,120) < = '2007-10-29';select * from aa
where convert(varchar(10),jf_time,120) > = '2007-09-29' and convert(varchar(10),jf_time,120) < = '2007-10-29';下面这两个语句却一样啊?
select * from aa
where convert(varchar(50),bb_time,112) > = '2007-09-29' and convert(varchar(50),bb_time,112) < = '2007-10-29';select * from aa
where convert(varchar(10),bb_time,112) > = '2007-09-29' and convert(varchar(50),bb_time,112) < = '2007-10-29';
与convert()的参数到底怎么用??
select * from aa
where convert(varchar(50),bb_time,120) > = '2007-09-29 ' and convert(varchar(50),bb_time,120) < = '2007-10-29 '; select * from aa
where convert(varchar(10),jf_time,120) > = '2007-09-29 ' and convert(varchar(10),jf_time,120) < = '2007-10-29 '; =================================================================
因為convert()帶120參數,會將小時分鐘秒等也帶進去
而112參數不會,只有yyyymmdd形式
select
convert(varchar(50),getdate(),120),
convert(varchar(10),getdate(),120),
convert(varchar(50),getdate(),112),
convert(varchar(10),getdate(),112)==============================
結果
2007-11-05 17:02:46
2007-11-05
20071105
20071105
select * from aa
where convert(varchar(50),bb_time,120) > = '2007-09-29 ' and convert(varchar(50),bb_time,120) < = '2007-10-29 '; select * from aa
where convert(varchar(10),jf_time,120) > = '2007-09-29 ' and convert(varchar(10),jf_time,120) < = '2007-10-29 ';
------------一个是bb_time 字段,一个是jf_time 字段????而下边那个都是bb_time 字段
select * from aa
where convert(varchar(50),bb_time,120) > = '2007-09-29 ' and convert(varchar(50),bb_time,120) < = '2007-10-29 '; select * from aa
where convert(varchar(10),jf_time,120) > = '2007-09-29 ' and convert(varchar(10),jf_time,120) < = '2007-10-29 '; =================================================================
因為convert()帶120參數,會將小時分鐘秒等也帶進去
而112參數不會,只有yyyymmdd形式==========================================================================
学习