Selecting from SQLExpress using datetime field

Can anyone tell me what is wrng with this code:

select * from membership where joined like 13/01/2006

'Joined' is a datetime field. There records in the table in this format. When I run this code it returns zero rows. Changikng 'like' to '=' makes n difference. Adding 00:00;00 creates an error, as does putting the value in quotes.

If I use '>' rows are returned but not just for the required data.

The joined field is not indexed and ordering the data does work. The primary index is on another field which has unique values/

Thanks in avance for any help.



Answer this question

Selecting from SQLExpress using datetime field

  • Maersa

    Thanks for the suggestion. It did not quite work but gave me the start I needed to find the solution. The convert style you had returned a date in a different format.

    This is the code I arrived at:

    select * from membership where convert(nchar(8),joined,112) like '20060113'

    I had not downloaded the SQL Online Books before now.

    Once again thanks for the pointer.


  • Robert Schmalz

    select * from membership where convert(char(8),joined,120) like '20060113'

  • Selecting from SQLExpress using datetime field