Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Summing Columns of Dates
Summing Columns of Dates
Rate Topic
Display Mode
Topic Options
Author
Message
pkaraffa
pkaraffa
Posted Saturday, August 04, 2012 3:14 PM
Grasshopper
Group: General Forum Members
Last Login: Saturday, January 05, 2013 7:06 PM
Points: 15,
Visits: 42
I have 2 columns of dates. What I need to do is to sum or count days in between. I know that there is the Datediff function. My problem is that I am trying to sum a startdate and an enddate. But if the start date starts on 6/1/2012 and ends on 6/1/2012 then I want to count this as 1. Can anyone please give me some guidance thanks in advance!
Post #1340220
Lynn Pettis
Lynn Pettis
Posted Saturday, August 04, 2012 4:47 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 4:21 PM
Points: 21,596,
Visits: 27,408
pkaraffa (8/4/2012)
I have 2 columns of dates. What I need to do is to sum or count days in between. I know that there is the Datediff function. My problem is that I am trying to sum a startdate and an enddate. But if the start date starts on 6/1/2012 and ends on 6/1/2012 then I want to count this as 1. Can anyone please give me some guidance thanks in advance!
DATEDIFF(dd,@StartDate,@EndDate) + 1
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1340225
demonfox
demonfox
Posted Sunday, August 05, 2012 2:03 AM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 6:46 PM
Points: 1,074,
Visits: 1,076
case when @StartDate<@EndDate then
DATEDIFF(dd,@StartDate,@EndDate) + 1
when @StartDate>@EndDate then DATEDIFF(dd,@StartDate,@EndDate) - 1 end
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1340248
pkaraffa
pkaraffa
Posted Sunday, August 05, 2012 2:35 PM
Grasshopper
Group: General Forum Members
Last Login: Saturday, January 05, 2013 7:06 PM
Points: 15,
Visits: 42
Thank you both worked great!
Post #1340292
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.