You can do the same thing in SQL...build queries upon queries. For example:
select * from table3
where fieldname2 in(
select fieldname2 from table2
where fieldname in(
select fieldname from table1
)
)
Main Topics
Browse All TopicsIn MS Access you build queries upon queries. You can put in parameters so you can pass user or program input into the queries. This where my problem is, building Views upon other Views in SQL with parameters. I know that Views cannot have parameters so you should use Stored Procedures. I am used to building complex queries in Access but I am stuck in SQL. For example I have a list of Employees with Punch In and Out dates with times. So I wrote a stored procedure below. This returns the values I need for the next step. Now I need to take that data (Q1) and do something to it and get (Q2) and then I need to take (Q1) and outer join it to (Q2) and get (Q3). Then I need to take (Q3) and do something to that and get (Q4). This was very easy to do in Access. If I have to construct some long text based solution in a stored procedure I will go nuts. How can I get the initial data I need with parameters and then continue with Views so I can build upon each one?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You are misunderstanding me, I know that you can build Queries upon Queries. My first Query/View/Stored Procedure has to return data from a table based on a From Date and a To Date. I want to get a data set from a table based on the date parameters. These parameters are not static. Once I have this data set then I can create all kinds of queries. My problem is that I don't know how link the parameter based data set to a query. That is, if I have a stored procedure that returns a data set based on parameters how can I use/link this data so I can use it in my Views? In MS Access I would just use a parameter based Query, but in SQL I don't know what to do.
By the last query (Q4).
****** Q1 ******
SELECT TmClkID, EmpID, Dt, EventType, Loc, YrMnDy
FROM dbo.fncRAWdataByDate('3/19
****** Q2 ******
SELECT EmpID, YrMnDy
FROM dbo.vwEvalData_10
GROUP BY EmpID, YrMnDy
HAVING (COUNT(EmpID) % 2 = 0)
****** Q3 ******
SELECT dbo.vwEvalData_10.*
FROM dbo.vwEvalData_10 INNER JOIN
dbo.vwEvalData_20 ON dbo.vwEvalData_10.EmpID = dbo.vwEvalData_20.EmpID AND dbo.vwEvalData_10.YrMnDy = dbo.vwEvalData_20.YrMnDy
****** Q4 ******
SELECT TOP (100) PERCENT outP.EmpID, outP.Dt, outP.EventType, DATEDIFF(mi, inP.Dt, outP.Dt) AS TmMn
FROM dbo.vwEvalData_30 AS inP INNER JOIN
dbo.vwEvalData_30 AS outP ON inP.EmpID = outP.EmpID AND outP.Dt > inP.Dt LEFT OUTER JOIN
dbo.vwEvalData_30 AS inbetween ON inP.EmpID = inbetween.EmpID AND inbetween.Dt > inP.Dt AND inbetween.Dt < outP.Dt
WHERE (inP.EventType = 1) AND (inbetween.EmpID IS NULL) AND (outP.EventType = 2)
ORDER BY inP.EmpID, inP.Dt
I am creating a report so the user will, via a web interface or MS Access, select the date range and then run the report. Here is the queries again with names:
****** Q1 (dbo.vwEvalData_10) ******
SELECT TmClkID, EmpID, Dt, EventType, Loc, YrMnDy
FROM dbo.fncRAWdataByDate('3/19
****** Q2 (dbo.vwEvalData_20) ******
SELECT EmpID, YrMnDy
FROM dbo.vwEvalData_10
GROUP BY EmpID, YrMnDy
HAVING (COUNT(EmpID) % 2 = 0)
****** Q3 (dbo.vwEvalData_30)******
SELECT dbo.vwEvalData_10.*
FROM dbo.vwEvalData_10 INNER JOIN
dbo.vwEvalData_20 ON dbo.vwEvalData_10.EmpID = dbo.vwEvalData_20.EmpID AND dbo.vwEvalData_10.YrMnDy = dbo.vwEvalData_20.YrMnDy
****** Q4 (dbo.vwEvalData_40)******
SELECT TOP (100) PERCENT outP.EmpID, outP.Dt, outP.EventType, DATEDIFF(mi, inP.Dt, outP.Dt) AS TmMn
FROM dbo.vwEvalData_30 AS inP INNER JOIN
dbo.vwEvalData_30 AS outP ON inP.EmpID = outP.EmpID AND outP.Dt > inP.Dt LEFT OUTER JOIN
dbo.vwEvalData_30 AS inbetween ON inP.EmpID = inbetween.EmpID AND inbetween.Dt > inP.Dt AND inbetween.Dt < outP.Dt
WHERE (inP.EventType = 1) AND (inbetween.EmpID IS NULL) AND (outP.EventType = 2)
ORDER BY inP.EmpID, inP.Dt
I guess at this point you tell me because I don't know what method or process to do this. If everything was in MS Access then my User Form would have hidden fields that would have the date that the query would read when it ran. Now that I am doing this using an MS Access interface I don't know how I would get these values form the form to the query. I don't know if the SQL statement would take the [Forms]![frm]![DateFrom], if your familar with MS Access.
Business Accounts
Answer for Membership
by: BriCrowePosted on 2008-03-21 at 10:05:40ID: 21181335
There might be another way to handle this without trying to duplicate the same logic from access. Starting from scratch please provide your table schema and the desired results.