关于sql查询分析器

来源:百度知道 编辑:UC知道 时间:2024/09/22 09:50:07
刚才我问了一个关于查询分析器的问题,现在又有一点问题请大家解决
我要从storage_inout_bills_history中的rq栏取2008全年的一项
日期栏的格式是2000-01-01 0:00我想取2008全年的可是用
select *
from storage_inout_bills_history
where left(rq,4) =‘2008'却取不出数来有高手知道为什么么?
另外取数还有要求要取dept_no_in中为109的,我知道语句是
and dept_no_in ='109'
然而还有要求
要取dh_no中为f2010300,f3010400,f2022300,f2020100,f2020700五项全部的内容语句应该怎么写呢?我写的
select *
from storage_inout_bills_history
where left(rq,4) =‘2008’
and dept_no_in ='109'
下面的怎么写啊 五项全部要

求高手回答
char(4),rq,120
能给我解释一下什么意思么


1楼、3楼都是正解
2楼明显是复制的1楼真没水平

select *
from storage_inout_bills_history
where convert(char(4),rq,120) =‘2008’
and dept_no_in ='109' and dh_no in ('f2010300','f3010400','f2022300','f2020100','f2020700')

RQ是不是日期类型,是的话应该这样:

select *
from storage_inout_bills_history
where year(rq) =2008
and dept_no_in =109
and dh_no in ('f2010300','f3010400','f2022300','f2020100','f2020700')

注意语句里面的引号、逗号、空白等各种符号都要使用英文的,你帖子的逗号就是错的。

select *
from storage_inout_bills_history
where year(rq) =2008
and dept_no_in ='109'
and dh_no in ('f2010300','f3010400','f2022300','f2020100','f2020700')