Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > selecting data of time format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-05-08, 00:54
tiger66 tiger66 is offline
Registered User
 
Join Date: Dec 2007
Posts: 24
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
Reply With Quote
  #2 (permalink)  
Old 01-05-08, 12:12
trvishi trvishi is offline
Registered User
 
Join Date: Sep 2003
Location: Switzerland
Posts: 371
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'
Reply With Quote
  #3 (permalink)  
Old 01-06-08, 01:35
tiger66 tiger66 is offline
Registered User
 
Join Date: Dec 2007
Posts: 24
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On