Click here to Skip to main content
15,888,461 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL connection in Visual studio 2012 Pin
Richard Deeming28-Oct-13 12:40
mveRichard Deeming28-Oct-13 12:40 
AnswerRe: SQL connection in Visual studio 2012 Pin
Bernhard Hiller29-Oct-13 22:02
Bernhard Hiller29-Oct-13 22:02 
QuestionCTE Query taking too long Pin
Richard.Berry10027-Oct-13 8:03
Richard.Berry10027-Oct-13 8:03 
AnswerRe: CTE Query taking too long Pin
Mycroft Holmes27-Oct-13 13:06
professionalMycroft Holmes27-Oct-13 13:06 
GeneralRe: CTE Query taking too long Pin
Richard.Berry10027-Oct-13 18:54
Richard.Berry10027-Oct-13 18:54 
GeneralRe: CTE Query taking too long Pin
Mycroft Holmes27-Oct-13 19:18
professionalMycroft Holmes27-Oct-13 19:18 
GeneralRe: CTE Query taking too long Pin
Richard.Berry10028-Oct-13 8:26
Richard.Berry10028-Oct-13 8:26 
GeneralRe: CTE Query taking too long Pin
Jörgen Andersson28-Oct-13 10:35
professionalJörgen Andersson28-Oct-13 10:35 
As the dateconversion seems to be the problem probably together with a bad plan I'd recommend that you minimize the number of conversions:
SQL
WITH Datetimes AS
(
    SELECT  GETDATE()as DateValue
    UNION ALL
    SELECT  DateValue -1
    FROM    Datetimes
    WHERE   DateValue -1 >= dateadd(d,-90,GETDATE())
)
,dates AS
(
    SELECT  DISTINCT convert(date,datevalue) AS ProdDate
    FROM    Datetimes
)
,trk AS
(
    SELECT  convert(date,DateCreated) as TrkDate
           ,allocated
    from    vektronix.[dbo].[Tracking] t
    where   [TrackingTypeId] = '5'
)
,trkgrouped as
(
    SELECT  trkdate
           ,SUM(allocated) as Tot
    FROM    trk
    GROUP BY trkdate
)

SELECT  ProdDate
       ,coalesce(Tot,0)as ProdQty
FROM    Dates D
left JOIN trkgrouped trk on trk.TrkDate = d.ProdDate
order by ProdDate desc
OPTION (MAXRECURSION 32747)
The purpose of the DISTINCT is to force the DatesCTE to be materialized.

But if you really want to boost the performance of the query you need to add convert(date,DateCreated) to vektronix.[dbo].[Tracking] as a calculated column and put an index on it.
The reasonable man adapts himself to the world; the unreasonable man adapts the world to himself.
Therefore all progress depends on the unreasonable man.
- George Bernard Shaw

GeneralRe: CTE Query taking too long Pin
Richard.Berry10028-Oct-13 18:39
Richard.Berry10028-Oct-13 18:39 
QuestionCount related Pin
Corporal Agarn25-Oct-13 5:37
professionalCorporal Agarn25-Oct-13 5:37 
AnswerRe: Count related Pin
Richard Deeming25-Oct-13 7:47
mveRichard Deeming25-Oct-13 7:47 
GeneralRe: Count related Pin
Corporal Agarn25-Oct-13 8:13
professionalCorporal Agarn25-Oct-13 8:13 
QuestionWhat is the format of the connection string used for mysql database access? Pin
Gbenbam24-Oct-13 15:59
Gbenbam24-Oct-13 15:59 
AnswerRe: What is the format of the connection string used for mysql database access? Pin
PIEBALDconsult24-Oct-13 17:33
mvePIEBALDconsult24-Oct-13 17:33 
AnswerRe: What is the format of the connection string used for mysql database access? Pin
coded00725-Oct-13 3:17
professionalcoded00725-Oct-13 3:17 
QuestionLINQ syntax Pin
vkEE24-Oct-13 3:24
vkEE24-Oct-13 3:24 
QuestionRe: LINQ syntax Pin
thatraja24-Oct-13 3:37
professionalthatraja24-Oct-13 3:37 
AnswerRe: LINQ syntax Pin
vkEE24-Oct-13 3:58
vkEE24-Oct-13 3:58 
GeneralRe: LINQ syntax Pin
Bernhard Hiller24-Oct-13 21:28
Bernhard Hiller24-Oct-13 21:28 
AnswerRe: LINQ syntax Pin
Richard Deeming24-Oct-13 4:25
mveRichard Deeming24-Oct-13 4:25 
NewsProblem Connecting To SQL from SOME Machines Pin
Kevin Marois22-Oct-13 9:29
professionalKevin Marois22-Oct-13 9:29 
AnswerRe: Problem Connecting To SQL from SOME Machines Pin
thatraja22-Oct-13 22:36
professionalthatraja22-Oct-13 22:36 
GeneralRe: Problem Connecting To SQL from SOME Machines Pin
jschell23-Oct-13 9:48
jschell23-Oct-13 9:48 
GeneralRe: Problem Connecting To SQL from SOME Machines Pin
Bernhard Hiller23-Oct-13 20:43
Bernhard Hiller23-Oct-13 20:43 
GeneralRe: Problem Connecting To SQL from SOME Machines Pin
jschell24-Oct-13 7:47
jschell24-Oct-13 7:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.