Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nizguy
Starting Member
37 Posts |
Posted - 2012-09-07 : 14:09:04
|
Here is what happens.When I hard coded the date to '8/8/12', It get me the result in less than 5 seconds. When I use the @FromDate variable, It gave me the same result but took over 2 minutes, I tried it many times, It took much longer to return the result.Does anyone know WHY?ThanksDECLARE @FromDate as smalldatetimeSET @FromDate = dateadd(day, -30, getdate()) SELECT Bill_num ,Pickup_date ,Shipper_Id, Shipper_name, Shipper_addr1 FROM BillWHERE --Pickup_date > @FromDate Pickup_date > '8/8/2012' and (Re_Weight_Class is not null and Re_Weight_Class <> '') |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-09-07 : 14:14:09
|
Take a look at this thread to see if the suggestions there would help you: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=177995When you use the variable, it ends up with a bad execution plan. All the suggestions are to trick query optimizer from getting stuck like that. |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
|
nizguy
Starting Member
37 Posts |
Posted - 2012-09-07 : 15:35:08
|
thank you all all these info |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
|
|
|
|