Click here to Skip to main content
15,887,477 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to calculate average of qty sold the last 6 months or less Pin
Klaus-Werner Konrad25-Mar-11 14:50
Klaus-Werner Konrad25-Mar-11 14:50 
AnswerRe: How to calculate average of qty sold the last 6 months or less Pin
Mycroft Holmes24-Mar-11 12:59
professionalMycroft Holmes24-Mar-11 12:59 
GeneralRe: How to calculate average of qty sold the last 6 months or less Pin
Joe Smith IX24-Mar-11 18:10
Joe Smith IX24-Mar-11 18:10 
QuestionFInd Sundays only Pin
rakeshs31223-Mar-11 21:25
rakeshs31223-Mar-11 21:25 
AnswerRe: FInd Sundays only Pin
Wendelius23-Mar-11 22:51
mentorWendelius23-Mar-11 22:51 
GeneralRe: FInd Sundays only Pin
J4amieC23-Mar-11 23:13
J4amieC23-Mar-11 23:13 
GeneralRe: FInd Sundays only Pin
Wendelius23-Mar-11 23:27
mentorWendelius23-Mar-11 23:27 
GeneralRe: FInd Sundays only [modified] Pin
J4amieC23-Mar-11 23:38
J4amieC23-Mar-11 23:38 
Quick and dirty trial. Not particularly scientific but gives you some idea. On my local instance of SQL Server, this script (note the long time frame to bump the execution time to something measurable):

DECLARE @start DATETIME = '1950-01-01'
DECLARE @end DATETIME = '2011-03-31'

;WITH dateRange (date)
AS
(
	SELECT
        @start Date
    UNION ALL
    SELECT
        DATEADD(day, 1, Date) Date
    FROM
        dateRange
    WHERE
        Date < @end
) 
SELECT * FROM dateRange WHERE DATEPART(WEEKDAY,date) = 1
OPTION (MAXRECURSION 32767);


returns immediately (<1sec)

Whereas this script:

DECLARE @start DATETIME = '1950-01-01'
DECLARE @end DATETIME = '2011-03-31'
DECLARE @dates TABLE (date DATETIME)

WHILE (@start <= @end) 
BEGIN
      INSERT INTO @dates VALUES (@start);
      SET @start = DATEADD(day, 1, @start);
   END;
SELECT * FROM @dates WHERE DATEPART(WEEKDAY,date) = 1


is still running 1min25seconds later after typing this message (Edit: Final execution time: 7m4s).

Check the actual execution plans for each to see why one is "horrible".

modified on Thursday, March 24, 2011 6:01 AM

GeneralRe: FInd Sundays only Pin
Wendelius24-Mar-11 0:09
mentorWendelius24-Mar-11 0:09 
GeneralRe: FInd Sundays only Pin
rakeshs31224-Mar-11 0:22
rakeshs31224-Mar-11 0:22 
GeneralRe: FInd Sundays only Pin
Wendelius24-Mar-11 4:05
mentorWendelius24-Mar-11 4:05 
AnswerRe: FInd Sundays only Pin
J4amieC23-Mar-11 23:12
J4amieC23-Mar-11 23:12 
QuestionNeed help with updating columns Pin
Slow Learner23-Mar-11 3:15
Slow Learner23-Mar-11 3:15 
AnswerRe: Need help with updating columns Pin
David Mujica23-Mar-11 3:34
David Mujica23-Mar-11 3:34 
GeneralRe: Need help with updating columns Pin
musefan23-Mar-11 6:09
musefan23-Mar-11 6:09 
AnswerRe: Need help with updating columns [modified] Pin
Wendelius23-Mar-11 3:37
mentorWendelius23-Mar-11 3:37 
GeneralRe: Need help with updating columns Pin
musefan23-Mar-11 6:10
musefan23-Mar-11 6:10 
GeneralRe: Need help with updating columns Pin
Wendelius23-Mar-11 6:15
mentorWendelius23-Mar-11 6:15 
AnswerRe: Need help with updating columns Pin
Klaus-Werner Konrad25-Mar-11 7:23
Klaus-Werner Konrad25-Mar-11 7:23 
QuestionCapture error return by MS Sql Pin
Hum Dum22-Mar-11 20:28
Hum Dum22-Mar-11 20:28 
AnswerRe: Capture error return by MS Sql Pin
Wendelius22-Mar-11 21:11
mentorWendelius22-Mar-11 21:11 
GeneralRe: Capture error return by MS Sql Pin
Hum Dum22-Mar-11 21:29
Hum Dum22-Mar-11 21:29 
GeneralRe: Capture error return by MS Sql Pin
Wendelius22-Mar-11 21:45
mentorWendelius22-Mar-11 21:45 
GeneralRe: Capture error return by MS Sql Pin
Hum Dum22-Mar-11 22:51
Hum Dum22-Mar-11 22:51 
GeneralRe: Capture error return by MS Sql Pin
Wendelius22-Mar-11 23:19
mentorWendelius22-Mar-11 23:19 

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.