有一个表,表中有“日期”字段,是字符型,格式为XXXX年XX月XX日是在程序中手动生成的。我想自定义时间段查询比如说:2005年01月到2005年05月之间的数据.请问、怎么查呀。
另外:
select * from Tablename where between 日期 like '2005年01月%' and 日期 like '2005年05月'这句有错吗
另外:
select * from Tablename where between 日期 like '2005年01月%' and 日期 like '2005年05月'这句有错吗
确定输入的字符串是等长的
把你输入的日期初始化(专门做函数完成)
譬如 function FormatDateForStart(Byval Tstring as string) as string
'*******************************
'把输入的2005-1 初始化为2005-01-01
'*******************************
end function
function FormatDateForEnd(Byval Tstring as string) as string
'*******************************
'把输入的2005-5 初始化为2005-05-31
'*******************************
end functionselect * from tablename where between '" & DateStart & "' and '" & DateEnd & "'
另外:
select * from Tablename where between 日期 like '2005年01月%' and 日期 like '2005年05月'
这句有错吗
这样处理
1.日期的数值让用户通过日期空间选择比如使用dtppick
2.把控件的日期格式设置为标准格式:yyyy-mm-nn
3. 使用大于小于来设置一条件:
比如: ddate >"2005-05" and ddate <"2005-06"
ddate >"2005-05-01" and ddate <"2005-06-04"
select * from tb
where format(日期,"YYYY年MM月") between '2005年01月' and '2005年05月'SQL server:
select * from tb
where convert(char(10),日期) between '2005年01月' and '2005年05月'试试看,没用过这样的字符日期格式
select * from tb
where 日期 between '2005年01月' and '2005年05月'
where left(日期,8) between '2005年01月' and '2005年05月'