Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    32

    Unanswered: selecting data of time format

    Hi all
    I am having some trouble writing a select statment that involves time.

    I have a field, which has time data (i.e Jan 08 2008 12:00AM)

    If I write my select statement like the following
    select * from db where date < (select convert(char(12), getdate()) || '12:00')
    , the sql works fine.

    However, now I have a variable @startTime which has value Jan 1 1900 12:00. I only wants to get the time.
    So, I change my statement to the following
    select * from db where date < (select convert(char(12),getdate()) || select convert(char(5), @startTime, 12))

    For some reason, it gives me the following error message (syntax error near select)

    Does anyone know why my statement doens't work anymore?

    Thanks in advance for your help

  2. #2
    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    443
    Quote Originally Posted by tiger66
    select * from db where date < (select convert(char(12),getdate()) || select convert(char(5), @startTime, 12))
    You can only have one select in a sub query.

    Whenever theres a null value, the date has Jan 1 1900

    So, Im guessing you want something like this.

    select * from db where date < getdate() OR date < @startTime
    where @startTime != 'Jan 1 1900'

  3. #3
    Join Date
    Dec 2007
    Posts
    32
    Thank you trvishi

    I didn't know subquery can only allow one select statment.

    I use one select statement in my query and it works now

Posting Permissions

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