Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How do I creaty a query which will use another paramter query?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-03-09 : 08:35:43
Jorge writes "Hello.
I'm sorry if this is basic but I was assigned the task of building a simple report generator and everything was going ok with Access until they told me we would had to support Sql Server.
My problem: in Acces I create 2 views with parameters .
The first view uses the second view in its sql statement (both work with parameters).
So i set the parameters values and call the first view (and everything works out just fine).
Now, in Sql Server a view with parameters in considered to be a stored procedure (right?!) so how can I do something like this:

Query1
SELECT * FROM QUERY2 WHERE ID=@parm1

QUERY2
SELECT * FROM XXx,xxx,xxx .... WHERE InitialDate=@parm2

Once again: in Acces I'm able to set the parameter values and run query1.
So the mai question is : how can I call a stored procedure so I can replicate these two queries?

Thanks very much for your attention and help.
Best Regards,
Jorge C.
rdc02271@yahoo.com"

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-09 : 08:43:45
If you want to keep separate stored procs then

Create a temp table

insert #a
exec s_QUERY2 @parm2

select ...
from ...
join #a on ...
where ID=@parm1
and ...

But you can probably combine into a single SP query

select *
from (select * from tbl where ID = @Parm1) a
where ID2 = @Parm2


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -