Click here to Skip to main content
15,898,587 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The following query shows no data but data is available in database. In database the datatype is datetime. The database field value is 2015-07-09 12:17:00.Thanks in advance.

SQL
SELECT     Smt_GoodsIssue.nCode, Smt_GoodsIssue.nIssNo, Smt_GoodsIssue.nItemcode, Smt_GoodsIssue.nIssQty, Smt_ItemMaster.cItemDes, Smt_ItemMaster.nItemBalQty, 
                      Smt_Sizes.cSize1, Smt_Dimension.cDimen, Smt_GoodsIssue.cUnit
FROM         Smt_GoodsIssue INNER JOIN
                      Smt_ItemMaster ON Smt_GoodsIssue.nItemcode = Smt_ItemMaster.nItemCode INNER JOIN
                      Smt_Sizes ON Smt_ItemMaster.nsize = Smt_Sizes.nCode INNER JOIN
                      Smt_Dimension ON Smt_ItemMaster.nDimec = Smt_Dimension.ndCode
where (Smt_GoodsIssue.dEntDAte between '@FromDate' and '@ToDate')
order by Smt_GoodsIssue.dEntDAte
Posted
Updated 12-Jul-15 0:26am
v3

Um.
SQL
where (Smt_GoodsIssue.dEntDAte between '09-jul-2015' and '09-Jul-2015')

So, when SQL parses the dates you give it into DATETIME values, what time of day do you think it will use?
Simply put, 09-Jul-2015 will be interpreted as 2015-07-09 00:00:00.0000 so the database column data will only ever match if it is entered precisely at midnight. Your example value is twelve hours and 17 minutes later, so it falls outside the "match" range.

I'd suggest that this might be a better approach:
SQL
where (Smt_GoodsIssue.dEntDAte between '09-jul-2015' and '10-Jul-2015')
Or better use DATEADD to offset a single value if you are in reality passing it as a parameterised value.
 
Share this answer
 
your datetime field contains date & time value.

cast the datetime field for date part only in where clause.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900