I am trying to get al the rows from table1 where datetime is between 9:00AM
yesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise it
should return all where datetime>9:00 AM today.
Is this possible as a query in sql2000? 3 9361
Fred (Fr**@hotmail.com) writes: I am trying to get al the rows from table1 where datetime is between 9:00AM yesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise it should return all where datetime>9:00 AM today.
SELECT ...
FROM tbl
WHERE datepart(hour, getdate()) >= 9 AND
datecol >= convert(char(8), getdate(), 112) + ' 09:00:00'
OR datepart(hour, getdate()) < 9 AND
datecol BETWEEN datediff(day, -1,
convert(char(8), getdate(), 112) + ' 09:00:00') AND
convert(char(8), getdate(), 112) + ' 09:00:00'
The recurring expression
convert(char(8), getdate(), 112) + ' 09:00:00'
could be put in a function for shorter code. However, this could be
expensive performancewise.
The above is not tested.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
"Fred" <Fr**@hotmail.com> wrote in message news:IN******************@news-server.bigpond.net.au... I am trying to get al the rows from table1 where datetime is between 9:00AM yesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise it should return all where datetime>9:00 AM today.
Is this possible as a query in sql2000?
Assume table T and datetime column dt.
SELECT *
FROM T
WHERE DATEPART(HOUR, CURRENT_TIMESTAMP) < 9 AND
dt BETWEEN
DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP - 1, 112))
AND
DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP, 112))
UNION ALL
SELECT *
FROM T
WHERE DATEPART(HOUR, CURRENT_TIMESTAMP) >= 9 AND
dt > DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP, 112))
or, alternatively,
SELECT *
FROM T
WHERE (DATEPART(HOUR, CURRENT_TIMESTAMP) >= 9 OR
(dt BETWEEN
DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP - 1, 112))
AND
DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP, 112))))
AND
(DATEPART(HOUR, CURRENT_TIMESTAMP) < 9 OR
dt > DATEADD(HOUR,
9,
CONVERT(CHAR(8), CURRENT_TIMESTAMP, 112)))
--
JAG
Thank you Erland and John. Perfect!
"John Gilson" <ja*@acm.org> wrote in message
news:t_*********************@twister.nyc.rr.com... "Fred" <Fr**@hotmail.com> wrote in message
news:IN******************@news-server.bigpond.net.au... I am trying to get al the rows from table1 where datetime is between
9:00AM yesterday and 9:00AM today if the time now is less than 9:00AM.
Otherwise it should return all where datetime>9:00 AM today.
Is this possible as a query in sql2000?
Assume table T and datetime column dt.
SELECT * FROM T WHERE DATEPART(HOUR, CURRENT_TIMESTAMP) < 9 AND dt BETWEEN DATEADD(HOUR, 9, CONVERT(CHAR(8),
CURRENT_TIMESTAMP - 1, 112)) AND DATEADD(HOUR, 9, CONVERT(CHAR(8),
CURRENT_TIMESTAMP, 112)) UNION ALL SELECT * FROM T WHERE DATEPART(HOUR, CURRENT_TIMESTAMP) >= 9 AND dt > DATEADD(HOUR, 9, CONVERT(CHAR(8),
CURRENT_TIMESTAMP, 112)) or, alternatively,
SELECT * FROM T WHERE (DATEPART(HOUR, CURRENT_TIMESTAMP) >= 9 OR (dt BETWEEN DATEADD(HOUR, 9, CONVERT(CHAR(8),
CURRENT_TIMESTAMP - 1, 112)) AND DATEADD(HOUR, 9, CONVERT(CHAR(8), CURRENT_TIMESTAMP,
112)))) AND (DATEPART(HOUR, CURRENT_TIMESTAMP) < 9 OR dt > DATEADD(HOUR, 9, CONVERT(CHAR(8),
CURRENT_TIMESTAMP, 112))) -- JAG
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sunny K |
last post by:
Hi guys,
whilst working on a project which I thought was nearly complete I have
come across a problem which was some how over seen, which I am hoping
one of you guys know how to resovle.
...
|
by: kevinold |
last post by:
Hello everyone,
I have a list of about 1600 employees that I'd like to have displayed
in a form. I'd like to make the "search" for the user as easy as
possible.
I ran across this:...
|
by: psql-mail |
last post by:
I am running a SELECT to get all tuples within a given date range. This
query is much slwoer than i expected - am i missing something?
I have a table 'meta' with a column 'in_date' of type...
|
by: Ker |
last post by:
I have a query that works great. It gives me the min for multiple
fields.
Within this query, I also need to get the max of some fields too.
I currently have output of
Date Name ...
|
by: Polly |
last post by:
I had a macro that ran a parameter query and created and opened an
Excel file with the system date as part of the file name, but I had to
change the file name by hand. So I converted the macro to...
|
by: MLH |
last post by:
Suppose the following...
Dim A as Date
A=#7/24/2005#
I wish to compare value of A against 2 other values:
1) 8/1/2005
2) 9/1/2005
Which is better and why...
First:
|
by: ronchese |
last post by:
Hi.
I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!
In one of my tests, I have a datatable with 1 row and...
|
by: Henning M |
last post by:
Hi all,
I having some problems with Access and selecting records between dates..
When I try this in access, it works fine!!
"Select * from Bilag Where Mdates Between #1/1/2006# And...
|
by: djflow |
last post by:
Hi!
II was wondering if you can help me with SQL query..
Below 7 separated select query works fine(only when they are retrieved separately)
But I want to combined them together and so that i...
|
by: plaforest |
last post by:
Hello All,
Thank you for your thoughtful consideration.
I am running Access 2000 (9.0.3821 SR-1)
This query works:
SELECT ,
FROM table1
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |