Re: timezones in select statement
jerball (jerball@xxxxxxxxx) 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@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
Relevant Pages
- Re: How to make correct join
... If this query does not work out, I suggest that you post the following: ... INSERT statements with sample data. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ... (comp.databases.ms-sqlserver) - Re: Very slow query
... with lots if information in Books Online, Books, Courses, the Net etc. ... While testing the query in QA, use the "Show Estimated Query Plan" feature. ... This is what I suggest you also pick up using Profiler. ... Tibor Karaszi, SQL Server MVP ... (microsoft.public.sqlserver.programming) - Re: Database Engine Tuning Advisor suggestion to replace syntax.
... What you said was what I first planned to say, but then I read the Books Online which implies that the batch is indeed reused, so I held back from saying that. ... the query optimizer will probably match the Transact-SQL statement in the second execution with the execution plan generated for the first execution. ... SQL Server does not have to compile the second statement." ... (microsoft.public.sqlserver.tools) - Re: Many to one Select
... It still possible to define a query that has maximum of columns needed, ... INSERT statements with sample data. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ... (comp.databases.ms-sqlserver) - Re: UPDATE query gives Incorrect Syntax error
... Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books ... ... No - no triggers on the table. ... Is it possible that a previous query has somehow become trapped and is ... (comp.databases.ms-sqlserver) |
|