?
Solved

Syntax for Duration, Max Date, Min Date

Posted on 2013-01-24
7
Medium Priority
?
779 Views
Last Modified: 2013-01-28
I am wrestling with a query and I need some expert help. I am trying to create four new fields in my select statement:

  ,MIN(SERVICE_DELIVERIES.SERVICE_PERIOD_START) AS SVCSTARTDT
  ,MAX(SERVICE_DELIVERIES.[SERVICE_PERIOD_START2]) AS SVCENDDR
  ,DATEDIFF(d, SVCSTARTDT), SVCENDDT)
  ,AVG(DATEDIFF)
 
FROM
tablename.fieldname INNER JOIN ON tablename.fieldname
WHERE
blah-blah-blah
GROUP BY
??????

I can't get Reporting Services to accept any of several variations on this theme.
What I need is to identify the earliest/latest service date (so I can explore a cohort of people getting certain services) and I need a new data element that gives me DURATION as an expression or function of Max - Min.  In a perfect world, I would be able to get for the DURATION data element a specific format of YY.YYY or YY.MM where the expression rounds up to the next month if even one day in the max month is a service date between or on Min/Max. (I'm looking for how many years and months a person got services in a program).  

Taking that one step further, I'd like to be able to get AVG_DURATION so I can use this in evaluating program tenure from date A to date B.

SO - to boil it all down, I need syntax/convention in T-SQL for Report Builder 3.0:

1.  MIN(SERVICE_DELIVERIES.SERVICE_PERIOD_START_DT) AS SVCSTARTDT
2.  MAX(SERVICE_DELIVERIES.SERVICE_PERIOD_START_DT) AS SVCENDDT
--Report Builder does NOT like using the same data element twice and I can't figure out how to differentiate the two--
3.  DURATION  (Difference between min and max date as YY,MM or YY.YYY)
4.  AVG_DURATION (self-evident)

Finally, I am using these in a query that has grouping applied, so which if any, and how, should these elements be represented in the GROUP BY clause?

Assistance VERY gratefully appreciated.
0
Comment
Question by:gberkeley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 600 total points
ID: 38816236
"SO - to boil it all down, I need syntax/convention in T-SQL for Report Builder 3.0:"

Why not to use SQL Stored procedure in the report instead? That's what I would do to simplify things (and SQL syntax) as you have way more posibilities like that and just use the SQL SP in your SSRS report
0
 

Author Comment

by:gberkeley
ID: 38816272
Hi lcohan,
Thanks for the fast response!
Perhaps a SPROC would be the better way to go. Unfortunately, that's WAY beyond my skill set.  If that's the right answer, then I'll need to wait for one of our DBAs to free up.  

Much appreciated,
j
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1400 total points
ID: 38825899
in the GROUP BY, you don't put the alias: AS SVCSTARTDT

anyhow, wouldn't this work
DURATION(  MIN( SERVICE_DELIVERIES.SERVICE_PERIOD_START_DT ) 
   , MAX(SERVICE_DELIVERIES.SERVICE_PERIOD_START_DT)  
  ) 

Open in new window

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:gberkeley
ID: 38827411
I think we're getting closer.... it seems it won't recognize Duration and it wants the DATEDIFF function. I just haven't been able to get the syntax straight that will let me use Min/max in same query.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38827449
the date difference in seconds, maybe?

DATEDIFF( second, MIN ( ... ) , MAX ( ... ) )
0
 

Author Comment

by:gberkeley
ID: 38827506
Report Builder still not cooperating.  I'm going to close out the question and refer it to the DBAs on my end; maybe they can figure it out.

Thanks, lcohan and angelIII!
0
 

Author Closing Comment

by:gberkeley
ID: 38827515
I really appreciated the fast responses and multiple attempts to assist.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question