Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

timezones in select statement
The situation is that I have a query where a [thing] is supposed to
end, in the sense that I don't want it to be pulled back in the query,
at a certain time (end_date), but that is determined by the timezone
that [thing] is located in (end_timezone).

Basically, I want to say:
1) If the current record has a timezone not equal to the current time
zone, which is mountain, then change the end_date being pulled back to
reflect the time zone
2) Then, only pull back records that are scheduled to end before that
time.

I know this statement isn't valid, but I'll post it here to try to
convey what I'm attempting:

select       end_date, end_timezone,
CASE	end_timezone
WHEN 'ET' THEN DATEADD(hh, 2, end_date)
WHEN 'CT' THEN DATEADD(hh, 1, end_date)
WHEN 'PT' THEN DATEADD(hh, -1, end_date)
ELSE end_date
END AS theEndDate
from	      offers
where	     end_timezone = 'PT'
and theEndDate >= {ts '2006-01-31 14:01:27'}

Of course, this statement fails. Any suggestions on how to do what I'm
trying to do?

Thanks!


Report this thread to moderator Post Follow-up to this message
Old Post
jerball
01-31-06 06:23 PM


Re: timezones in select statement
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can't use an expression (the CASE expression) from the SELECT clause
as part of the WHERE clause criteria, 'cuz the WHERE criteria is
evaluated before the SELECT columns are returned.  Therefore, use a date
column in the WHERE criteria.  E.g.:

WHERE end_date >= '2006-01-31 14:01:27'

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ9/ lCIechKqOuFEgEQKbHwC
 faitFAiSAnc7qDOuopSI
j1cJpw98AoPx4
 W9a72aZdML7ftMsgIKIZ
ynqF
=dwNQ
-----END PGP SIGNATURE-----



jerball  wrote:
> The situation is that I have a query where a [thing] is supposed to
> end, in the sense that I don't want it to be pulled back in the query,
> at a certain time (end_date), but that is determined by the timezone
> that [thing] is located in (end_timezone).
>
> Basically, I want to say:
> 1) If the current record has a timezone not equal to the current time
> zone, which is mountain, then change the end_date being pulled back to
> reflect the time zone
> 2) Then, only pull back records that are scheduled to end before that
> time.
>
> I know this statement isn't valid, but I'll post it here to try to
> convey what I'm attempting:
>
> select       end_date, end_timezone,
> 	        CASE	end_timezone
> 		        WHEN 'ET' THEN DATEADD(hh, 2, end_date)
> 		        WHEN 'CT' THEN DATEADD(hh, 1, end_date)
> 		        WHEN 'PT' THEN DATEADD(hh, -1, end_date)
> 		        ELSE end_date
> 	        END AS theEndDate
> from	      offers
> where	     end_timezone = 'PT'
> 	        and theEndDate >= {ts '2006-01-31 14:01:27'}
>
> Of course, this statement fails. Any suggestions on how to do what I'm
> trying to do?

Report this thread to moderator Post Follow-up to this message
Old Post
MGFoster
02-01-06 01:23 AM


Re: timezones in select statement
jerball (jerball@gmail.com)  writes:
> The situation is that I have a query where a [thing] is supposed to
> end, in the sense that I don't want it to be pulled back in the query,
> at a certain time (end_date), but that is determined by the timezone
> that [thing] is located in (end_timezone).
>
> Basically, I want to say:
> 1) If the current record has a timezone not equal to the current time
> zone, which is mountain, then change the end_date being pulled back to
> reflect the time zone
> 2) Then, only pull back records that are scheduled to end before that
> time.
>
> I know this statement isn't valid, but I'll post it here to try to
> convey what I'm attempting:
>
> select       end_date, end_timezone,
>              CASE     end_timezone
>                   WHEN 'ET' THEN DATEADD(hh, 2, end_date)
>                   WHEN 'CT' THEN DATEADD(hh, 1, end_date)
>                   WHEN 'PT' THEN DATEADD(hh, -1, end_date)
>                   ELSE end_date
>              END AS theEndDate
> from           offers
> where          end_timezone = 'PT'
>              and theEndDate >= {ts '2006-01-31 14:01:27'}
>
> Of course, this statement fails. Any suggestions on how to do what I'm
> trying to do?

How does if fail? Do you get an error message? Do you get unexpcted
result? Of course, since you constrain end_timezone to PT in the
WHERE condition, the CASE expression appears somewhat superfluous.

For this type of questions it is always a good idea to post:

1) CREATE TABLE statement(s) for the table(s) you are using.
2) INSERT statements with sample data.
3) The desired result given the sample.

This can help to improve the accuracy of the answers you get considerably.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
02-01-06 01:24 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 05:39 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006