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
 General SQL Server Forums
 New to SQL Server Programming
 Using Cursor in SQL Stored Procedure

Author  Topic 

jauner
Starting Member

19 Posts

Posted - 2009-11-03 : 12:14:08
I have 2 sql stored procedures that I would like to combine into one. My thought is to use a reportset table within the procedure and to create a type field. Such as l for the first set and o for the second set. Can someone tell me how I could accomplish this?

I have put the sql statements below:

1st one:


select
co.co_num,
co.cust_num,
co_line,
coitem.ref_num,
coitem.ref_line_suf,
name,
due_date,
item.item,
drawing_nbr,
qty_ordered,
uf_shippingtolerance,
qty_shipped,
coitem.stat
from
co, custaddr, coitem, item
where
co.cust_num = custaddr.cust_num and
co.cust_seq = custaddr.cust_seq and
co.co_num = coitem.co_num and
coitem.item = item.item and
due_date >= @startdate and due_date <= @enddate and
coitem.stat not in('F','C') and coitem.ref_type = 'J'


2nd one:

select
job.job,
job.suffix,
job.ord_num,
job.ord_line,
jobroute.oper_num,
wc.description as wc,
jobmatl.item,
jobroute.qty_received,
jobroute.qty_complete,
jobroute.qty_scrapped,
jobroute.qty_moved,
start_date,
end_date

From
job,jrt_sch, jobroute, jobmatl, wc
Where
job.job = jrt_sch.job and
job.suffix = jrt_sch.suffix and
job.job = jobroute.job and
job.suffix = jobroute.suffix and
job.job = jobmatl.job and
job.suffix = jobmatl.suffix and
jrt_sch.oper_num = jobmatl.oper_num and
jrt_sch.oper_num = jobroute.oper_num and
jobroute.wc = wc.wc

order by job.job asc, job.suffix desc, jobroute.oper_num asc


They would be linked by job.ord_num = co.co_num and coitem.co_line = job.ord_line
   

- Advertisement -