| Author |
Topic |
|
svallamreddy
Starting Member
4 Posts |
Posted - 2008-03-12 : 05:42:39
|
| Hi, In my query where clause I am using between to get data. Because of time in the data I need to eliminate that and compare, how can I eliminate. my where clause is as below. due to that my query performance is falling down. please help.CONVERT(DATETIME, CONVERT(CHAR(20), OpportunityDate,110)) BETWEEN CONVERT(CHAR(20),@FDate,110) AND CONVERT(CHAR(20),@TDate,110)ThanksSreenu |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-12 : 05:47:37
|
don't convert to char for this...DATEADD(DAY,DATEDIFF(DAY,0,OpportunityDate),0) BETWEEN DATEADD(DAY,DATEDIFF(DAY,0,@FDate),0) and DATEADD(DAY,DATEDIFF(DAY,0,@TDate),0) Em |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-12 : 05:49:50
|
actually... do the variables you're passing have a time as well? if not then just...DATEADD(DAY,DATEDIFF(DAY,0,OpportunityDate),0) BETWEEN @FDate and @TDate Em |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 05:54:23
|
Don't even touch the OpportunityDate column!It makes it impossible to utilize a present index.And style 110 is a very bad choice!Look here, if you want all records dated May 15, 2007 through July 9, 2007 use thisSET @fDate = '20070515'SET @tDate = '20070710'SELECT * FROM Table1WHERE OpportunityDate >= @fDateAND OpportunityDate < @TDate E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 05:57:50
|
Of, if the @tDate is passed as "July 9, 2007" from the client application, useSELECT * FROM Table1WHERE OpportunityDate >= @fDateAND OpportunityDate < dateadd(day, 1, @TDate) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-03-12 : 06:11:11
|
| Is that better, worse or no different to...SELECT *FROM table1WHEREDATEDIFF(DAY, @fDate, OpportunityDate) >= 0AND DATEDIFF(DAY, opportunityDate, @TDate) >= 0-------------Charlie |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 06:15:00
|
Whenever you make a calculation over an indexed column, it renders the index useless.So you suggestion is as bas as the others, performance wise.Logically they are the same, ie they return the same result, only slower... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
svallamreddy
Starting Member
4 Posts |
Posted - 2008-03-12 : 07:04:39
|
Dear Thank you so much,Its excellet, ThanksSreenuquote: Originally posted by Peso Of, if the @tDate is passed as "July 9, 2007" from the client application, useSELECT * FROM Table1WHERE OpportunityDate >= @fDateAND OpportunityDate < dateadd(day, 1, @TDate) E 12°55'05.25"N 56°04'39.16"
|
 |
|
|
|
|
|