Results 1 to 5 of 5

Thread: query problem

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    Unanswered: query problem

    i have a msde 2000 database, and one of the field are filled by datetime with the format "yyyy-mm-dd hh:mm:ss".
    I make a query like this:
    "select * from mytable where myfield like '%2006-06-15%'"
    but i didn't get any record for the result and i have make it sure that there are lot of records with that value in myfield. The main problem is the char "-" that separate the date value, becouse if i make a query :
    "select * from mytable" then i get all of my records.
    Is there any suggest to solf my problem?

  2. #2
    Join Date
    Dec 2004
    Posts
    46
    why u want a like clause on a date time field.

    Instead try myfield >= '2006-06-15' and myfield < '2006-06-16'

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Is your date field a datetime datatype, or is it a string?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Your date is actually formatted more like 0x000097E2008BE35B even though SQL Server displays it as 2006-06-16 13:29 when it returns a value to the client machine. You can use string patterns on it, and SQL Server will happily convert for you, but it isn't efficient and worse yet it isn't always predictable.

    The suggested syntax that Ronin gave is both efficient and predictable.

    -PatP

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    0x000097E2008BE35B???

    Is is that late already? I missed my 0x000097E200A4CB80 meeting!
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •