Viewing 15 posts - 961 through 975 (of 2,171 total)
If your Tally table is big enough, you can do without the days & hours combination and go for hours directly.
SELECTCOUNT(*)
FROMmaster..spt_values AS h
WHEREh.Type = 'p'
AND h.Number < DATEDIFF(HOUR, @Date1, @Date2)
AND...
May 8, 2008 at 6:26 am
Sure. No problems. This is not one of the most efficient queries, but it gets the work done and it was fast to write.
DECLARE@Date1 DATETIME,
@Date2 DATETIME
SELECT@Date1 = '20080610',
@Date2 = '20080711'
SELECTCOUNT(*)
FROMmaster..spt_values...
May 8, 2008 at 4:06 am
Excellent!
Nice work and faster than my suggestion.
Michaels improved version of Jeffs original query also works with dates only (time set to 00:00:00).
This is a tool I'll keep. Thanks.
I found a...
May 8, 2008 at 1:15 am
If speed it of importance, you may not want to use SET ANSI_WARNINGS OFF.
Why? Beacuse all settings altering the current connection triggers a recompile.
http://www.novicksoftware.com/Articles/minimizing-stored-procedure-recompilation-page2.htm
Quote from Experts-Exchange "performance killer"
In SQL 2000...
May 8, 2008 at 12:56 am
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
May 8, 2008 at 12:42 am
Somewhat shorter code
SELECTCOUNT(*)
FROMmaster..spt_values AS d
INNER JOINmaster..spt_values AS h ON h.Type = 'p'
WHEREd.Type = 'p'
AND d.Number <= DATEDIFF(DAY, @Date1, @Date2)
AND h.Number BETWEEN 0 AND 23
AND DATEADD(HOUR, h.Number, d.Number + @Date1) <...
May 7, 2008 at 8:20 am
Here is something that only uses the "JOIN" once.
INSERT[Log]
SELECTy.theDateTime,
y.theSP,
y.theNULL,
CASE
WHEN x.theIdentifier = 0 THEN 'Record Not Found'
ELSE CAST(x.theCount AS VARCHAR(12)) + ' calculation done.'
END AS theMessage
FROM(
SELECTGETDATE() AS theDateTime,
#pfm.sp AS theSP,
NULL AS...
May 7, 2008 at 8:03 am
Thank you. You admit they produce the same result.
Now we can move forward.
May 7, 2008 at 7:59 am
Michael, what if starttime and endtime is NOT on weekend as op wrote originally?
Jeff, what if starttime AND endtime is ON weekend as op wrote originally?
DECLARE@Date1 DATETIME,
@Date2 DATETIME
SELECT@Date1 = '20061018...
May 7, 2008 at 7:44 am
Try this first to see if it produces the wanted result, THEN we can talk about optimization.
INSERT[Log]
SELECTGETDATE(),
#pfm.sp,
NULL,
CAST(COUNT(#r1.sp) AS VARCHAR(12)) + ' calculation done.'
FROM#pfm
LEFT JOIN#r1 ON #r1.sp = #pfm.sp
WHERE#pfm.Flag = 'S'
GROUP...
May 7, 2008 at 7:24 am
Wait a minute... Your title is Senior Software Engineer and this is the zillionth question you have?
May 7, 2008 at 7:17 am
I don't think DBCC PINTABLE is available in SQL Server 2005, so that approach is a dead end.
May 7, 2008 at 12:31 am
And with integers as parameter values
SELECTDATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), -1) AS LastOfPreviousMonth,
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) AS FirstOfCurrentMonth,
DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE()), -1) AS LastOfCurrentMonth,
DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE()), 0) AS FirstOfNextMonth
April 30, 2008 at 12:57 am
SELECTDATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '18991231') AS LastOfPreviousMonth,
DATEADD(MONTH, DATEDIFF(MONTH, '19000101', GETDATE()), '19000101') AS FirstOfCurrentMonth,
DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '18991231') AS LastOfCurrentMonth,
DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '19000101') AS FirstOfNextMonth
April 30, 2008 at 12:56 am
Viewing 15 posts - 961 through 975 (of 2,171 total)