Viewing 15 posts - 46 through 60 (of 413 total)
If that's the only field, then I'm a bit puzzled as to how you determine when you have a CostCenterID and when you have a CostCenterName. Also, you have no...
February 20, 2006 at 1:57 am
My formula
datediff(d, '19000101', @dateTo)/7 - datediff(d, '19000102', @dateFrom)/7
doesn't depend on datefirst settings and server collation. Like I have said before, it returns the number of Mondays between @dateFrom and @dateTo,...
February 20, 2006 at 1:03 am
So I've noticed - neither does mine
February 18, 2006 at 5:40 am
You could also try the script below.
I think what Sergiy suggests is that you make timeinterval (see below) a calculated and indexed column on mytable and then run the last...
February 17, 2006 at 7:58 am
I see. No, nothing's wrong. You include the second date but not the first. I thought you included both dates (like I do in my query). I apologize, your query works perfectly.
But......
February 17, 2006 at 7:26 am
What I meant was that you could easily get (-1)/7, although this wasn't clear from what I wrote.
I assumed you wanted to add 1 to the formula you stated perviously....
February 17, 2006 at 6:35 am
Sergiy, I believe the following is correct:
select case when
Datediff(dd, @startDate, @endDate - (@@Datefirst+Datepart(dw,@endDate)-2) %7) < 0
then 0 else
Datediff(dd, @startDate, @endDate - (@@Datefirst+Datepart(dw,@endDate)-2) %7) / 7 + 1
end
The division and...
February 17, 2006 at 5:32 am
Sergiy, I don't believe your formula is correct if @StartDate=@EndDate='20051231'.
Jeff, I think this modification of your formula works:
DATEDIFF(wk,@startDate,@endDate)
-CASE WHEN DATENAME(dw,@endDate)='Sunday' THEN 1 ELSE 0 END
+CASE WHEN DATENAME(dw,@startDate)='Monday' THEN 1 ELSE...
February 17, 2006 at 4:23 am
Jeff, your formula doesn't work if the start date is a Sunday - e.g if @startdate = @enddate which is a Sunday, it will return -1.
I believe the following works...
February 17, 2006 at 3:01 am
Note that the output of your function depends on the value of @@DATEFIRST:
declare @DateFirst int
select @DateFirst = @@DATEFIRST
set datefirst 1
select dbo.Monday('2006-02-13','2006-02-20') --Returns 2
set datefirst 7
select dbo.Monday('2006-02-13','2006-02-20') -- Returns 1 (incorrect)
set datefirst...
February 16, 2006 at 6:43 am
Something like this?
create proc countMondays
(
@FromDate datetime,
@ToDate datetime,
@NumberOfMondays int output
)
as
select @NumberOfMondays = (datediff(d, '20060213', @ToDate) + 1)/7 - datediff(d, '20060213', @FromDate)/7
go
declare @count int
exec countMondays '20000101', '20001231', @count...
February 16, 2006 at 5:47 am
I don't quite understand what you're saying. As an example, to calculate the number of Mondays in the year 2000, do as follows:
select (datediff(d, '20060213', '20001231') + 1)/7 - datediff(d,...
February 16, 2006 at 5:23 am
I think this will give the number of Mondays between the two dates (both inclusive). 20060213 can be replaced by any Monday...
select (datediff(d, '20060213', @Date2) + 1)/7 - datediff(d, '20060213', @Date1)/7
February 16, 2006 at 4:57 am
Or this one, perhaps:
select t1.Value, max(cast(t2.Value as int))
from @Table1 t1
left join @Table2 t2
on t1.Value like t2.Value + '%'
group by t1.Value
I (and JeffB, I think) assume you want the first n...
February 16, 2006 at 3:19 am
What are the definitions of the tables DataToBeParsed and OrderCatalog?
February 16, 2006 at 2:47 am
Viewing 15 posts - 46 through 60 (of 413 total)