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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-05-05 : 14:51:46
|
| reema rughani writes "HiI have a fairly large SP that takes about 5 min to return 289 rows but if i run the select and other bits outside of the sp (by declaring the parameters and settign them to the same values used to declare the sp) it takes 20 seconds. There is no difference between the two expect that one is the stored procedure. Sp is below and below that is the sql i ran:SET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spsun_rp_COM001_PI_v1_OrdersShippedByBusiness]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[spsun_rp_COM001_PI_v1_OrdersShippedByBusiness]GOCREATE PROCEDURE spsun_rp_COM001_PI_v1_OrdersShippedByBusiness ( @DateFrom varchar(8) , @DateTo varchar(8) , @Cosmetics Varchar(50), @Pigments Varchar(50), @Textiles Varchar(50), @IDO Varchar(50), @Interco Varchar(50), @Merchant Varchar(50), @Invoiced Varchar(50), @NotInvoiced Varchar(50), @Company varchar(30), @Site varchar(4) , @SalesOrderRep varchar(15), @SalesAgent varchar(30), @TPName varchar(30), @TPNetwork varchar(30), @TPCountry varchar(30), @GenResc varchar(35), @ResourceForm varchar(15), @Parm20 Varchar(50) )AS/******************************************************************************** File: spsun_rp_COM001_PI_v1_OrdersShippedByBusiness.sql** Name: spsun_rp_COM001_PI_v1_OrdersShippedByBusiness** Desc: **** Auth: Greg Bones** Date: 1 May 2002********************************************************************************* Change History********************************************************************************* Date: Author: Description:** -------- -------- ---------------------------------------** 20020517 NyborgM Adjusted to PIreports** 20030203 NyborgM ISNULL inserted in where statement** 20030212 NyborgM New selection criteria on Currency ** 20030217 NyborgM Wrong join to Invoice corrected ** 20030326 NyborgM Order site changed to shipSite*******************************************************************************//*DECLARE @DateFrom varchar(8) DECLARE @DateTo varchar(8) DECLARE @Cosmetics Varchar(50)DECLARE @Pigments Varchar(50)DECLARE @Textiles Varchar(50)DECLARE @IDO Varchar(50)DECLARE @Interco Varchar(50)DECLARE @Merchant Varchar(50)DECLARE @Invoiced Varchar(50)DECLARE @NotInvoiced Varchar(50)DECLARE @Company varchar(30)DECLARE @Site varchar(4) DECLARE @SalesOrderRep varchar(15)DECLARE @SalesAgent varchar(30)DECLARE @TPName varchar(30)DECLARE @TPNetwork varchar(30)DECLARE @TPCountry varchar(30)DECLARE @GenResc varchar(35)DECLARE @ResourceForm varchar(15) DECLARE @Parm20 Varchar(50)SET @DateFrom = '20021001'SET @DateTo = '20021231' SET @Cosmetics = 'TRUE'SET @Pigments = 'TRUE'SET @Textiles = 'TRUE'SET @IDO = 'TRUE'SET @Interco = 'TRUE'SET @Merchant = 'TRUE'SET @Invoiced = 'TRUE'SET @NotInvoiced = 'TRUE'SET @Company = 'WAGB'SET @Site = '%' SET @SalesOrderRep = '%'SET @SalesAgent = '%'SET @TPName = '%'SET @TPNetwork = '%'SET @TPCountry = '%'SET @GenResc = '%'SET @ResourceForm = '%' SET @Parm20 = '%'DROP TABLE #OrdersDROP TABLE #Currency*/BEGINCREATE TABLE #Orders ( [ShipDate] [datetime] NULL , [Bus] [varchar] (15) NULL , [Co] [varchar] (30) NULL , [Site] [varchar] (4) NULL , [SunOrder] [varchar] (15) NULL , [OrderObjectID] [int] NULL , [Rep] [varchar] (15) NULL , [Agent] [varchar] (30) NULL , [TPObjectID] [int] NULL , [TP] [varchar] (30) NULL , [TPN |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2004-05-05 : 14:51:46
|
| And we truncate at 4,000 characters. You'll have to repost in this thread. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-05 : 14:56:47
|
| Have you tried recompiling the stored procedure?Tara |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-05 : 19:31:24
|
| It's hard to troubleshoot without then entire query. A guess though is that it's recompiling every single time it runs because of those temp tables. Just a guess though. It's also possible it's getting stuck with a bad plan though. Have you looked at the execution plan both ways and seen where they are different?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
rughanir
Starting Member
4 Posts |
Posted - 2004-05-06 : 03:21:39
|
| Hi SP Reattached. we have tried optimising the sp (mainly the first select). how do i recomplile an sp? i have never done that.Thanks ReemaCREATE PROCEDURE spsun_rp_COM001_PI_v1_OrdersShippedByBusiness ( @DateFrom varchar(8) , @DateTo varchar(8) , @Cosmetics Varchar(50), @Pigments Varchar(50), @Textiles Varchar(50), @IDO Varchar(50), @Interco Varchar(50), @Merchant Varchar(50), @Invoiced Varchar(50), @NotInvoiced Varchar(50), @Company varchar(30), @Site varchar(4) , @SalesOrderRep varchar(15), @SalesAgent varchar(30), @TPName varchar(30), @TPNetwork varchar(30), @TPCountry varchar(30), @GenResc varchar(35), @ResourceForm varchar(15), @Parm20 Varchar(50) )ASBEGINCREATE TABLE #Orders ( [ShipDate] [datetime] NULL , [Bus] [varchar] (15) NULL , [Co] [varchar] (30) NULL , [Site] [varchar] (4) NULL , [SunOrder] [varchar] (15) NULL , [OrderObjectID] [int] NULL , [Rep] [varchar] (15) NULL , [Agent] [varchar] (30) NULL , [TPObjectID] [int] NULL , [TP] [varchar] (30) NULL , [TPName] [varchar] (30) NULL , [TPNet] [varchar] (30) NULL , [TPCity] [varchar] (30) NULL , [TPCtry] [varchar] (30) NULL , [TPOrder] [varchar] (30) NULL , [GenResc] [varchar] (35) NULL , [ResourceObjectID] [int] NULL , [Resc] [varchar] (35) NULL , [RescSite] [varchar] (4) NULL , [LineSequenceNumber] [int] NULL , [DelivSequenceNumber] [int] NULL , [Lot] [varchar] (20) NULL , [Pkg] [varchar] (20) NULL , [RescForm] [varchar] (15) NULL , [TotPrice] [float] NULL , [TotPriceUSD] [float] NULL , [UnitPrice] [float] NULL , [Cur] [varchar] (3) NULL , [ExchaRate] [float] NULL , [OrderDelivObjectID] [int] NULL , [ShipKg] [float] NULL , [InvoiceDate] [datetime] NULL , [Invoice] [varchar] (15) NULL, [TPType] [varchar] (10) NULL , [RescLen] [int] NULL ) END/**************************************************************Orders for shipping**************************************************************/BEGININSERT INTO #Orders ( ShipDate , Bus , Co , Site , SunOrder , OrderObjectID , Rep , TPObjectID , TP , TPName , TPNet , TPCity , TPCtry , TPOrder , ResourceObjectID , Resc , Lot , RescSite , LineSequenceNumber , DelivSequenceNumber, RescForm , TotPrice , Cur , OrderDelivObjectID , UnitPrice , ShipKg, TPType, RescLen ) SELECT ShipLine.ActyDate , fdBasResc.CatCodesCode10 , coOrderSumry.SellCmpny , coOrderDeliv.ShipSite , coOrderSumry.OrderOrdName , coOrderSumry.ObjectID , fdTradingPartne.Description2 , fdTradingPartne.ObjectID , fdTradingPartne.TP , fdTradingPartne.Description , PrimaryNetTPNName , fdContact.PrimAddrCity , fdContact.PrimAddrCntry , coOrderDeliv.CustPONum , coOrderLineItem.OrdRescObjectID , coOrderLineItem.OrdResc , ShipLine.Lot , coOrderLineItem.OrdRescSite , coOrderLineItem.SequenceNumber , coOrderDeliv.SequenceNumber, fdBasResc.CatCodesCode6 , 0 , coOrderDeliv.UnitPriceCur , coOrderDeliv.ObjectID , coOrderDeliv.UnitPriceCurAmt , ShipLine.AltQty, fdTPType.Description2 , ISNULL(AOCOSTFIELDS.aoResLen, 0) FROM coOrderSumry (NOLOCK)INNER JOIN coOrderLineItem (NOLOCK) ON coOrderSumry.ObjectID = coOrderLineItem.ParentObjectID INNER JOIN coOrderDeliv (NOLOCK) ON coOrderLineItem.ObjectID = coOrderDeliv.ParentObjectIDINNER JOIN ( SELECT inShippingLineI.ActyDate , inShippingLineI.Lot , SUM(inShippingLineI.AltQty) AS AltQty , inShippingLineI.LogDocNum , inShippingLineI.LogDocRlsNum , inShippingLineI.LogDocLineNum FROM inShippingLineI (NOLOCK) WHERE CONVERT(varchar, inShippingLineI.ActyDate, 112) BETWEEN @DateFrom AND @DateTo GROUP BY inShippingLineI.ActyDate , inShippingLineI.Lot , inShippingLineI.LogDocNum , inShippingLineI.LogDocRlsNum , inShippingLineI.LogDocLineNum ) ShipLine ON (ShipLine.LogDocNum = coOrderSumry.OrderOrdName AND ShipLine.LogDocRlsNum = coOrderDeliv.SequenceNumber AND CONVERT(int,ShipLine.LogDocLineNum) = coOrderLineItem.SequenceNumber)INNER JOIN fdBasResc (NOLOCK) ON coOrderLineItem.OrdRescObjectID = fdBasResc.ObjectIDINNER JOIN fdAddOn (NOLOCK) ON fdAddOn.ParentObjectID = fdBasResc.ObjectIDINNER JOIN AOCOSTFIELDS (NOLOCK) ON AOCOSTFIELDS.fdAddOnID = fdAddOn.ObjectIDINNER JOIN fdTradingPartne (NOLOCK) ON coOrderDeliv.ShipToTPObjectID = fdTradingPartne.ObjectIDINNER JOIN fdTPType (NOLOCK) ON fdTPType.ObjectID = fdTradingPartne.TPTypeObjectIDINNER JOIN fdShipToRole (NOLOCK) ON fdTradingPartne.ObjectID = fdShipToRole.ParentObjectIDINNER JOIN fdContact (NOLOCK) ON fdShipToRole.ContactObjectID = fdContact.ObjectIDWHERE ISNULL(coOrderSumry.SellCmpny, '') LIKE @CompanyAND ISNULL(coOrderDeliv.ShipSite, '') LIKE @SiteAND ISNULL(fdTradingPartne.Description2, '') LIKE @SalesOrderRepAND ISNULL(fdTradingPartne.Description, '') LIKE @TPNameAND IsNULL(PrimaryNetTPNName, '') LIKE @TPNetworkAND ISNULL(fdContact.PrimAddrCntry, '') LIKE @TPCountryAND ISNULL(fdBasResc.CatCodesCode6, '') LIKE @ResourceFormORDER BY coOrderDeliv.ActShipDateEND/**************************************************************Orders for returns**************************************************************/BEGININSERT INTO #Orders ( ShipDate , Bus , Co , Site , SunOrder , OrderObjectID , Rep , TPObjectID , TP , TPName , TPNet , TPCity , TPCtry , TPOrder , ResourceObjectID , Resc , Lot , RescSite , LineSequenceNumber , DelivSequenceNumber, RescForm , TotPrice , Cur , OrderDelivObjectID , UnitPrice , ShipKg, TPType, RescLen ) SELECT RecLine.ActyDate , fdBasResc.CatCodesCode10 , coOrderSumry.SellCmpny , coOrderDeliv.ShipSite , coOrderSumry.OrderOrdName , coOrderSumry.ObjectID , fdTradingPartne.Description2 , fdTradingPartne.ObjectID , fdTradingPartne.TP , fdTradingPartne.Description , PrimaryNetTPNName , fdContact.PrimAddrCity , fdContact.PrimAddrCntry , coOrderDeliv.CustPONum , coOrderLineItem.OrdRescObjectID , coOrderLineItem.OrdResc , RecLine.Lot , coOrderLineItem.OrdRescSite , coOrderLineItem.SequenceNumber , coOrderDeliv.SequenceNumber, fdBasResc.CatCodesCode6 , 0 , coOrderDeliv.UnitPriceCur , coOrderDeliv.ObjectID , coOrderDeliv.UnitPriceCurAmt , RecLine.AltQty * -1, fdTPType.Description2 , ISNULL(AOCOSTFIELDS.aoResLen, 0) FROM coOrderSumry (NOLOCK)INNER JOIN coOrderLineItem (NOLOCK) ON coOrderSumry.ObjectID = coOrderLineItem.ParentObjectID INNER JOIN coOrderDeliv (NOLOCK) ON coOrderLineItem.ObjectID = coOrderDeliv.ParentObjectIDINNER JOIN ( SELECT inReceivingLine.ActyDate , inReceivingLine.Lot , SUM(inReceivingLine.AltQty) AS AltQty , inReceivingLine.LogDocNum , inReceivingLine.LogDocRelNum , inReceivingLine.LogDocLine FROM inReceivingLine (NOLOCK) WHERE CONVERT(varchar, inReceivingLine.ActyDate, 112) BETWEEN @DateFrom AND @DateTo GROUP BY inReceivingLine.ActyDate , inReceivingLine.Lot , inReceivingLine.LogDocNum , inReceivingLine.LogDocRelNum , inReceivingLine.LogDocLine ) RecLine ON (RecLine.LogDocNum = coOrderSumry.OrderOrdName AND RecLine.LogDocRelNum = coOrderDeliv.SequenceNumber AND CONVERT(int,RecLine.LogDocLine) = coOrderLineItem.SequenceNumber)INNER JOIN fdBasResc (NOLOCK) ON coOrderLineItem.OrdRescObjectID = fdBasResc.ObjectIDINNER JOIN fdAddOn (NOLOCK) ON fdAddOn.ParentObjectID = fdBasResc.ObjectIDINNER JOIN AOCOSTFIELDS (NOLOCK) ON AOCOSTFIELDS.fdAddOnID = fdAddOn.ObjectIDINNER JOIN fdTradingPartne (NOLOCK) ON coOrderDeliv.ShipToTPObjectID = fdTradingPartne.ObjectIDINNER JOIN fdTPType (NOLOCK) ON fdTPType.ObjectID = fdTradingPartne.TPTypeObjectIDINNER JOIN fdShipToRole (NOLOCK) ON fdTradingPartne.ObjectID = fdShipToRole.ParentObjectIDINNER JOIN fdContact (NOLOCK) ON fdShipToRole.ContactObjectID = fdContact.ObjectIDWHERE coOrderDeliv.delivtype = '3'AND ISNULL(coOrderSumry.SellCmpny, '') LIKE @CompanyAND ISNULL(coOrderDeliv.ShipSite, '') LIKE @SiteAND ISNULL(fdTradingPartne.Description2, '') LIKE @SalesOrderRepAND ISNULL(fdTradingPartne.Description, '') LIKE @TPNameAND IsNULL(PrimaryNetTPNName, '') LIKE @TPNetworkAND ISNULL(fdContact.PrimAddrCntry, '') LIKE @TPCountryAND ISNULL(fdBasResc.CatCodesCode6, '') LIKE @ResourceFormORDER BY coOrderDeliv.ActShipDateEND/*****************************************************************************Updating with Resource Length for resources not in FGNP*****************************************************************************/BEGINUPDATE #OrdersSET RescLen = CHARINDEX('_',#Orders.Resc)-1FROM #OrdersWHERE CHARINDEX('_',#Orders.Resc) <> 0AND #Orders.RescLen = 0END/*****************************************************************************Updating with Genericresource*****************************************************************************/BEGINUPDATE #OrdersSET GenResc = SUBSTRING(#Orders.Resc,1,RescLen)FROM #OrdersWHERE #Orders.RescLen <> 0END/*****************************************************************************Delete lines if not equal to parm in GenResc*****************************************************************************/BEGINDELETEFROM #OrdersWHERE NOT #Orders.GenResc LIKE @GenResc END/**************************************************************Update Total Price**************************************************************/BEGINUPDATE #OrdersSET TotPrice = UnitPrice * ShipKgFROM #OrdersEND/**************************************************************Update Sales Agent Information**************************************************************/BEGINUPDATE #OrdersSET Agent = fdContact.DescriptionFROM #OrdersINNER JOIN fdTradingPartne (NOLOCK) ON #Orders.TPObjectID = fdTradingPartne.ObjectIDINNER JOIN fdCommissionsRo (NOLOCK) ON fdTradingPartne.CommisRoleObjectID = fdCommissionsRo.ObjectIDINNER JOIN fdContact (NOLOCK) ON fdCommissionsRo.ContactObjectID = fdContact.ObjectIDEND/**************************************************************Update Packaging Information**************************************************************/BEGINUPDATE #OrdersSET Pkg = RIGHT(fdBasResc.ResourceUK, aoCostFields.aoPackLen)FROM #OrdersINNER JOIN fdBasResc (NOLOCK) ON #Orders.ResourceObjectID = fdBasResc.ObjectIDINNER JOIN aoCostFields (NOLOCK) ON fdBasResc.ObjectID = aoCostFields.ParentObjectIDEND/**************************************************************Update Invoice Information**************************************************************/BEGINUPDATE #OrdersSET InvoiceDate = coInvcSumry.InvcDate, Invoice = coInvcSumry.InvcUKInvcFROM #OrdersINNER JOIN coInvcOrder (NOLOCK) ON #Orders.OrderObjectID = coInvcOrder.OrderUKObjectIDINNER JOIN coInvcSumry (NOLOCK) ON coInvcSumry.ObjectID = coInvcOrder.ParentObjectIDINNER JOIN coInvcLine (NOLOCK) ON (coInvcOrder.ObjectID = coInvcLine.ParentObjectID AND #Orders.LineSequenceNumber = coInvcLine.OrdLin AND #Orders.DelivSequenceNumber = coInvcLine.OrdDel)END/**************************************************************Calculate Exchange Rate into USD**************************************************************/BEGINSELECT Ord.OrderDelivObjectID , Ord.Cur , bcCurrencyConv.CurConvToCur , ISNULL(Ord.ShipDate, GetDate()) 'ShipDate', ISNULL(bcCurrConvRate.ConvRate,1) 'ConvRate'INTO #CurrencyFROM #Orders OrdINNER JOIN bcCurrencyConv (NOLOCK) ON Ord.Cur = bcCurrencyConv.CurConvFromCurINNER JOIN bcCurrConvRate (NOLOCK) ON bcCurrencyConv.ObjectID = bcCurrConvRate.ParentObjectIDWHERE bcCurrencyConv.CurConvToCur = 'USD' AND bcCurrConvRate.StartDate = (SELECT MAX(bcCurrConvRate.StartDate) FROM #Orders INNER JOIN bcCurrencyConv (NOLOCK) ON #Orders.Cur = bcCurrencyConv.CurConvFromCur INNER JOIN bcCurrConvRate (NOLOCK) ON bcCurrencyConv.ObjectID = bcCurrConvRate.ParentObjectID WHERE bcCurrencyConv.CurConvToCur = 'USD' AND Ord.OrderDelivObjectID = #Orders.OrderDelivObjectID AND bcCurrConvRate.StartDate < ISNULL(#Orders.ShipDate, GetDate()) GROUP BY bcCurrencyConv.CurConvToCur)GROUP BY Ord.OrderDelivObjectID , Ord.Cur , bcCurrencyConv.CurConvToCur , ISNULL(Ord.ShipDate, GetDate()), ISNULL(bcCurrConvRate.ConvRate,1)END/**************************************************************Set ExchaRate to USD**************************************************************/BEGINUPDATE #OrdersSET ExchaRate = #Currency.ConvRateFROM #OrdersINNER JOIN #Currency ON #Orders.OrderDelivObjectID = #Currency.OrderDelivObjectIDEND/**************************************************************Set ExchaRate to 1 for USD**************************************************************/BEGINUPDATE #OrdersSET ExchaRate = 1WHERE Cur = 'USD'END/**************************************************************Calculate TotPrice for USD**************************************************************/BEGINUPDATE #OrdersSET TotPriceUSD = TotPrice * ExchaRateEND/**************************************************************Select to list**************************************************************/BEGINSELECT ShipDate, Bus, Co, Site, SunOrder, Rep, Agent, TP, TPName, TPNet, TPCity, TPCtry, TPOrder, GenResc, Resc, RescSite, Lot, Pkg, RescForm, TotPrice, TotPriceUSD, UnitPrice, Cur, ExchaRate, ShipKg, InvoiceDate, InvoiceFROM #OrdersWHERE IsNull(Agent, ' ') LIKE @SalesAgentAND ((not InvoiceDate IS NULL and @Invoiced = 'TRUE')or (InvoiceDate IS NULL and @NotInvoiced = 'TRUE'))AND ((TPType = 'IC' AND @Interco = 'TRUE')OR (TPType = 'ID' AND @IDO = 'TRUE')OR (TPType = 'TR' AND @Merchant = 'TRUE'))AND ((Bus = 'COSMETICS' AND @COSMETICS = 'TRUE')or (Bus = 'TEXTILES' AND @TEXTILEs = 'TRUE')or (Bus = 'PIGMENTS' AND @PIGMENTS = 'TRUE'))ORDER BY Bus, TPCtry, TP, Resc, ShipDateENDGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOGRANT EXECUTE ON [dbo].[spsun_rp_COM001_PI_v1_OrdersShippedByBusiness] TO [public]GO |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-06 : 03:31:16
|
| how do i recomplile an sp? i have never done that.EXEC sp_recompile 'proc_name'MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
rughanir
Starting Member
4 Posts |
Posted - 2004-05-06 : 04:08:23
|
| Hi I have tried recompiling but i have had no luck. The Sp itself still takes over 5 min to return 289 rows. And againt the direct sql with the same parameters declared and set, returns after 30 seconds. i am so stuck on this! Hope someone can help.Reema |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2004-05-06 : 07:44:03
|
| Hi Reema, you might want to try running DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS to make sure the old execution plan is flushed from memory before you run it again. Have you compared the execution plans of the proc and the query, perhaps there is something very obviously different between the two? I've seen some similar issues with parallelism on servers with more than one processor.Also, try replacing the temp table with a table variable, that is a lot less likely to cause a recompile every time the proc is run.OS |
 |
|
|
rughanir
Starting Member
4 Posts |
Posted - 2004-05-06 : 11:41:05
|
| HI I have tried everythign now. I have compared the direct sql exec plan to the sp exec plan and there is virtually no difference. I have also tried DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS but again that made no difference. I will now try to change the temp table to a table variable (which should be interesting seeign as i have never done one). Thanks for all your help and advise. I will re-post with any results, good or bad.. he he! R |
 |
|
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-05-06 : 12:09:23
|
| Try CREATE PROCEDURE spsun_rp_COM001_PI_v1_OrdersShippedByBusiness (...) WITH RECOMPILE AS That will cause the proc to be recompiled every time it is run. Usually that is not a good idea, but the query plan is generated for a proc the first time it is executed. That plan is based on the values passed at the time it is run. If different parameters are used for subsequent calls, the original query plan may no longer be optimal. WITH RECOMPILE will add overhead when invoking it but may help in the long run.You might also try changing:CONVERT(varchar, inShippingLineI.ActyDate, 112) BETWEEN @DateFrom AND @DateToto inShippingLineI.ActyDate BETWEEN convert(datetime,@DateFrom) AND convert(datetime,@DateTo)in the 2 insert statements. Converting ActyDate to varchar prevents an index on ActyDate from being used.Cheers |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-06 : 14:48:22
|
quote: Originally posted by rughanir HI I have tried everythign now. I have compared the direct sql exec plan to the sp exec plan and there is virtually no difference. I have also tried DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS but again that made no difference. I will now try to change the temp table to a table variable (which should be interesting seeign as i have never done one). Thanks for all your help and advise. I will re-post with any results, good or bad.. he he! R
It's a piece of cake:DECLARE @table TABLE(column1 INT,column2 VARCHAR(55))MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|
|
|