# Database Discussions > Reporting Services >  How do I run sub queries on a Dataset?

## Don.

Hi Guys,

I have a dataset which could potentially be fairly large depending on the date range that the user selects, so Id prefer to run it only once, and get my results from that...
(In SQL, I created a temp table and ran my subqueries against that.)

This dataset will mainly be composed of dates and I have to get the average time between dates. ie

dsMain Results

Company, Contact, Posting_Date, Matched_Date, Sent_Date, Interview_Date, etc...
Company, Contact, Posting_Date, Matched_Date, Sent_Date, Interview_Date, etc...
Company, Contact, Posting_Date, Matched_Date, Sent_Date, Interview_Date, etc...
Company, Contact, Posting_Date, Matched_Date, Sent_Date, Interview_Date, etc...
etc...

Most of my Subqueries would need to get the average date between dates

The query below is what I use in SQL to get the difference between Average Matched_date and Average SENT_DATE

SubQuery

(Select DATEDIFF(Hour, CAST(AVG(CAST(MATCHED_DATE AS FLOAT)) AS DATETIME), CAST(AVG(CAST(SENT_DATE AS FLOAT)) AS DATETIME))
From #tbl
Where (Matched_Date is not null and Matched_Date <> '')
AND (Sent_Date is not null and Sent_Date <> '') 
AND Company_Name IN ('COMPANYNAME')) AS "CompanyName",


I spent ages trying to convert this subquery to an expression, but it doesnt look like expressions allow the CAST function.

Thanks in advance.

----------

