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! 2 3535
-----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/lCIechKqOuFEgEQKbHwCfaitFAiSAnc7qDOuopSIj1cJpw98Ao Px4
W9a72aZdML7ftMsgIKIZynqF
=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?
jerball (je*****@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, es****@sommarskog.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael |
last post by:
I would like to set the timezone of a thread to allow me
to calculate the UTC time for data sourced from a number
of time zones. Although this can be done in C and C++, I
annot find how to do...
|
by: Robert Treat |
last post by:
I am trying to figure out if there is a way to determine the timezones
supported in postgresql from within the database. If you look at...
|
by: Martijn van Oosterhout |
last post by:
Hi,
The operating system I run (Linux) comes with many, many timezone files
for many different places in the world. For example:
$ TZ='Australia/Sydney' date
Fri Oct 8 06:15:31 EST 2004
$...
|
by: Flack |
last post by:
Hey guys,
I need to compare two times that the user selects. The user selects the
hour, date, and timezone (which can be either NY, LN, or HK timezones).
How can I compare two dates of...
|
by: Alex |
last post by:
Hi
My website is hosted in the States (EST), but the website itself is
targeted for UK users (GMT).
How can I offset the time so that the server reports it as GMT when my
ASP.NET app needs to...
| |
by: =?Utf-8?B?U3R1?= |
last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled
web services. We are making use of the javascript proxies generated by
ASP.NET Ajax.
The problem we have is that the...
|
by: Daz |
last post by:
Hello everyone.
I am creating a JavaScript project which will allow users to see what
time it is in other countries. I am wondering if there's any way to
have the server work this out, without...
|
by: David T. Ashley |
last post by:
In a web database (PHP), per user, I'd like to allow each user to specify
their timezone (this would change how times are adjusted for display for
that user).
How do I enumerate all possible...
|
by: Sanjay |
last post by:
Hi All,
I am using pytz.common_timezones to populate the timezone combo box of
some user registration form. But as it has so many timezones (around
400), it is a bit confusing to the users. Is...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |