How to convert sql query into SSRS expression?

I have a query that works, but now I need to make an expression so I can add to a Chart.

SELECT Datepart(day, LogDate) AS DayNum, SUM(Efficiency)/24 AS DayAverage FROM xyz
WHERE CAST(LogDate AS Date) BETWEEN '20150301' AND '20150309'
GROUP BY Datepart(day, LogDate)


Thanks much.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
Explain for us what the gap is between the T-SQL you have posted above, assuming it works as an SSRS data set fine, and being able to use it in a chart control.
DonAuthor Commented:

Yes, the dataset works fine, but I cannot put a second dataset into a CHART.
Microsoft SQL Server Report Designer

Error:  Only fields from the current dataset can be added.

My next idea:

In Chart Data:
Values:  Click +
Select:   Expression

(Here is where I copy and paste by sql statement)

=DATEPART("day", Fields!LogDate.Value) AS DayNum, SUM(Fields!Efficiency.Value) / 24 AS DayAverage
FROM            XYZ
WHERE        (CAST(LogDate AS Date) BETWEEN '20150301' AND '20150309')

Problem #1:   Doesn't like AS
Problem #2:   Casting Dates.

Does this help?

Thank you so very much for looking.

p.s.  If you have another idea, please suggest!

Thanks again.
PortletPaulEE Topic AdvisorCommented:
You can avoid the CAST in your where clause by avoiding "between", which you should always do for date ranges:

WHERE       ( LogDate >= '20150301' AND LogDate < '20150310' )

& do please note I pushed the higher date up one day!

see: "Beware of Between"

the best practice with date and time ranges is to avoid BETWEEN and to always use the form:

WHERE col >= '20120101' AND col < '20120201'
This form works with all types and all precisions, regardless of whether the time part is applicable.
Itzik Ben-Gan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DonAuthor Commented:
Thank you for the Beware of BETWEEN article.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.