怎么写sql? [英] how to write the sql?
问题描述
我写了下面的sql,
Hi,
I wrote sql as below,
select * from STS_VEHICLE_RUNNING_STATUS
WHERE VRS_DEVICEID='ST0001' AND VRS_UTCTIME BETWEEN '7/2/2012' AND '10/9/2012'
它检索值.但排除10/9/2012的值.
如果我有一个包含StartDate列和EndDate列的表,我可以生成一个查询,该查询返回范围内包括每天的集合.我可以使用表变量并执行一些过程代码,但我想知道是否可以在查询中进行操作.
例如. StartDate = 1/1/2010,EndDate = 1/5/2010,结果为:
•2010年1月1日
•2010年1月2日
•1/3/2010
•2010年4月4日
•1/5/2010
...对于表中具有StartDate和EndDate列的每一行.
请帮助...
谢谢..
It retrieve values.But exclude the values for 10/9/2012.
If I have a table with a StartDate column and an EndDate column can I produce a query that returns a set including every day in the range. I could use a table variable and do some procedural code but I''d like to know if there''s a way to do it in a query.
E.g. StartDate = 1/1/2010, EndDate = 1/5/2010, result would be:
•1/1/2010
•1/2/2010
•1/3/2010
•1/4/2010
•1/5/2010
...for every row in the table that has the StartDate and EndDate columns.
plz help...
Thanks..
推荐答案
我想您可以使用更简单的查询,
You can use simpler query I guess,
SELECT *
FROM STS_VEHICLE_RUNNING_STATUS
WHERE
CONVERT(VARCHAR(10), VRS_UTCTIME ,101) >= CONVERT(VARCHAR(10) ,@YourDate,101)
AND CONVERT(VARCHAR(10) ,VRS_UTCTIME ,101) <= CONVERT(VARCHAR(10) ,@YourDate,101)
AND VRS_DEVICEID='ST0001'
其中应包括日期.
Milind
This should include the dates.
Milind
写
'11/9/2012'
而不是
'10/9/2012'
这是因为时间分量取为00:00:00(即时间的开始).
或
您将替换为
This is because time component is taken as 00:00:00(ie starting of time).
or
You replace by
'10/9/2012 12:00:00 PM'
这篇关于怎么写sql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!