Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > optimal selecti...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 11027 of 11221
Post > Topic >>

optimal selection of all records for a certain month (illegal dates

by metaperl <metaperl@[EMAIL PROTECTED] > May 8, 2008 at 11:09 AM

First a simple question: Is it allowed to provide a date range that
has an illegal date. For instance

SELECT * FROM tbl WHERE datex >= 2007-09-01 AND datex <= 2007-09-31

Now for my real question. I have a table with a column named
last_update_date that is indexed. I would like to find all records in
this table where last_update_date has a certain year and month.

The actual date which has the year and month is an in a programming
language string, so I am doing substring operations to find the proper
month and day:

SELECT
    *
FROM
    xfer_tbl
WHERE
    AND  MONTH( last_update_date ) = CONVERT(INT, SUBSTRING('$
{START_DATE}', 5, 2))
    AND  YEAR( last_update_date ) =    CONVERT(INT, SUBSTRING('$
{START_DATE}', 1, 4))

But as you can see, this does not take advantage of the databases (MS
SQL 2000) indexing power does it? It would be better to use >= and <=
as in my first sample query, but then I run the risk of using an
illegal date.
 




 3 Posts in Topic:
optimal selection of all records for a certain month (illegal da
metaperl <metaperl@[EM  2008-05-08 11:09:26 
Re: optimal selection of all records for a certain month (illega
metaperl <metaperl@[EM  2008-05-08 11:50:19 
Re: optimal selection of all records for a certain month (illega
"Plamen Ratchev"  2008-05-08 17:17:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Wed Jul 9 0:24:22 CDT 2008.