新手……问关于SQL模糊查询语句
select count(字段) from 表名where 字段名like '%条件%’
想查询出这张表里面1月2月的数据,数据是xxxx年x月x日!!!
求模糊查询出这张表1月2月的所有数据!谢谢
[解决办法]
你的意思是说你的日期用了字符串来存?
[解决办法]
- SQL code
create table tb(id int,shijian nvarchar(10))insert into tbselect 1,'2011年1月2日' union allselect 2,'2010年1月2日' union allselect 3,'2010年1月3日' select * From tb where shijian like '____年1月2日'
[解决办法]
- SQL code
select * from 表名where 字段名 like '%月’
[解决办法]
- SQL code
select * from 表名 where 日期字段 between '2011-01-01' and '2011-02-29'
[解决办法]
- SQL code
select count(*) from 表名 where 字段名 like '%年1月%' or 字段名 like '%年2月%'
[解决办法]
- SQL code
create table tb(dt nvarchar(12))insert into tb select '2010年5月9日'insert into tb select '2010年12月11日'insert into tb select '2010年1月1日' --1insert into tb select '2011年2月15日' --2insert into tb select '2012年5月22日'insert into tb select '2011年11月14日'goselect count(*) from tb where dt like '%年1月%' or dt like '%年2月%'/*-----------2(1 行受影响)*/godrop table tb
[解决办法]
- SQL code
select count(*) from tb where convert(char(10),dt,20) between '2011-01-01' and '2011-02-29'把日期格式化一下!
[解决办法]
- SQL code
select count(*) from tb where shijian like '----年[12]月%'