Jump to content

SQL DateTime - SQL Compact Database


kevin.upshaw

Recommended Posts

Hi. Wonder if anyone can help. Am trying to retrieve records from my order table from a date inputted by the user. I've done all the SQL on my site up to here - this one is really baffling me through. Query: SELECT * FROM [order] WHERE orderDateTime LIKE '04/05/2012%'; However, it doesn't return any values - see my data types in my table below: post-95813-0-75391400-1336248495_thumb.png As you can see from the data view there is data applicable in there to my query: post-95813-0-32721200-1336248496_thumb.png Am at a loss. Can anyone help? Thanks. Kevin

Link to comment
Share on other sites

Hi. I have tried the following query: SELECT * FROM [order] WHERE orderDateTime LIKE '%2012-05-04%' Unfortunately that doesn't return anything. However if I run this query: SELECT * FROM [order] WHERE orderDateTime LIKE '%2012%' It pulls back all my orders. Its as soon as I put a "-" or a "/" it just doesn't return any values. Kev

Link to comment
Share on other sites

Try this:

SELECT * FROM [order] WHERE orderDateTime LIKE '04_05_2012%'

Link to comment
Share on other sites

Hi. Thanks for your help. I managed to get around it using this code: var extractOrderInformation = "SELECT * FROM [order] WHERE CONVERT(NVARCHAR, orderdatetime, 103) BETWEEN CONVERT(NVARCHAR, @0, 103) AND CONVERT(NVARCHAR, @1, 103)"; Thanks again. Kev

Link to comment
Share on other sites

Another solution might be this: SELECT * FROM [order] WHERE orderDateTime LIKE '%2012%05%04%'
Remember that you can use the underscore to match exactly one character rather than zero or more: %2012_05_04%
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...