Quote:
quote:Originally posted by Mitch
This is "foggy" in my mind: What I need to understand is how to do something in SQL that I used to do in MS Access, namely use a query that takes a parameter(s) that is used within another query that itself takes a different parameter(s).
|
You can't do the same thing in SQL Server. There is no such thing as a "...query that takes a parameter...". There are lots of things (almost all bad :D) you can do in Access that you can't do exactly the same way in SQL Server.
There is no such thing as a "Query" in SQL Server. We refer to queries (lowercase) as being the resultset of a SELECT statement, or the act that we do when we execute such a statement in a tool like Query Analyzer. Instead of Queries which are stored in the database as in Access, SQL Server has Views and Stored Procedures.
Stored procedures may take parameters and may return resultsets, but they may just as well have no parameters and return nothing at all.
Views are virtual tables - they act just like a table which contains rows made up of columns. You select the rows and columns from the view in the same way you would select from a table. You JOIN a View to other Views and/or tables.
The rough equivalent of what you are looking for is that you would pass parameters to a Stored procedure which would execute a SELECT statement returning a resultset. This resultset would be constructed by JOINing your tables and views together as appropriate and then using your parameters as expressions in the WHERE clause to select the appropriate rows from the JOINs of your various tables and views. You might also use your parameters to direct the flow of execution in the Stored Procedure, depending on your requirements.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com