Which is more optimized for a select query view or stored procedure

Which is more optimized for a select query view or stored procedure

Post by Suresh Gladston » Wed, 20 Feb 2002 20:49:59



Hi All,
 I need a clarification about the performance issue of  a
view and a stored procedure,say for eg this the view that
ive written...WHICH BY EXPLANATION IS NOTHING BUT A SELECT
STATEMENT FROM AROUND 7-8 TABLES IN SQL SERVER..

My point of argument is ,since this following set of
statements involves only select querries views would be
more optimized than stored procedure for the same selects
as below like
CREATE  procedure VW_ChildCheckList
AS
etc..etc

Can anyone breif me about the execute plan for this query
and also the detailing of performance of VIEWS and stored
procedures in different situation,and  the precise
information about  IS A VIEW MORE OPTIMIZED FOR SELECT
STATEMENTS???
 The query is

CREATE view VW_ChildCheckList
AS
select getdate() as SYSDATE, A.*,B.* From
(select A.*,B.* from
(select A.*,B.* from
(select a.*,b.* from
( select c.Child_id,convert(numeric(30,0),timestamp + 0)
as
timeflag,c.firstname,c.lastname,c.middlename,c.aka,c.DOB,c.
Sex,c.Child_SSN,c.Court_Date,

c.Ambulatory,c.Ambul_Date,c.Prn_meds,c.Physical,c.Dental,c.
Ltr602sent,c.county_cnt,c.Agreement,

c.Agreemt_fh,c.MED_CONSNT,c.md_cnst_fh,c.id_emrgncy,c.id_em
rg_fh,c.n_s_plan,

c.n_s_pln_fh,c.pers_right,c.prs_rgt_fh,c.prs_rgt_bk,c.prope
rty,c.proprty_fh,c.proprty_bk,

c.md_exam_fh,c.md_exam_bk,c.immunizatn,c.immuniz_fh,c.tb_te
st,c.tb_test_fh,c.dental_fh,

c.store_meds,c.stor_md_fh,c.stor_md_bk,c.intak_stdy,c.bios_
sent,c.court_rpt,c.excpt_24hr,c.dschrg_rec,

dschrg_lst,c.staf_visit,c.billed,c.c_signs,c.ar_signs,c.sw_
7days,c.sw_30days,c.sw_notouch,c.safe_cash,

c.afdc,c.rev_c_chkl,c.rev_fh_ckl,c.over18,c.adopt,c.clothin
g,c.asmt_rpt,c.prn_med_fh,

c.agency_id,c.dsch_pol_o,c.dsch_pol_h,c.provider_id,c.cur_f
phome_id,c.cur_gh_id,
 c.cur_sw_id,c.cur_guardian_id,
 c.admit,c.discharge,c.move_in,c.move_out
 from child c
 )A LEFT OUTER JOIN
 (SELECT gh_id,ffa_id as gh_ffa_id, gh_name from GH)
 B ON A.cur_gh_id=B.gh_id
) A left outer join
(SELECT b.fphome_id ,a.ffa_id as fp_ffa_id, a.ffa_office  
from FFA a,fphome b
where a.ffa_id=b.ffa_id)
B on A.cur_fphome_id=B.fphome_id)
A LEFT OUTER JOIN
(select b.*_id ,c.fphome_id as fphomeID,d.lastname as
FP_Lastname ,d.firstname as FP_Firstname ,b.firstname as
Spouse  
 from *s b,*s d,fp c  where  b.*_id =
c.*_id and b.gender='M' AND d.GENDER='F' and
 b.lastname=d.lastname)
B ON A.fphome_id=B.fphomeID)
A LEFT OUTER JOIN
(SELECT  e.employee_id, a.*_id as *ID, a.LastName
AS SwLastName, a.FirstName AS SwFirstName
 FROM *S a ,employee e where a.*_id=e.*_id)
B ON B.employee_id=A.cur_sw_id

Thanks and Regards

Suresh Gladstone

 
 
 

1. How can I optimize this stored procedures / queries?

Hello,

I have the following tables:

orders:
id, customer_id...

orders_report:
order_id, datetime, user, state

example:
orders_report
...
1004 / 01.10.2000 10:30 / SmithJ / sales dept.
1007 / 01.10.2000 10:38 / MillerE / sales dept.
1002 / 01.10.2000 11:03 / WithA / production
1008 / 01.10.2000 11:18 / SmithJ / sales dept.
1004 / 01.10.2000 13:27 / WithA / production
1002 / 01.10.2000 13:40 / LongC / shipping dept.
1007 / 01.10.2000 14:03 / WithA / production
 ...

I need a query for the following information:
order number and the current state
f.e. order n 1002 is in the shipping department since 13:40

...
1002 / shipping dept. / 01.10.2000 13:40
1004 / production / 01.10.2000 13:27
1007 / production / 01.10.2000 14:03
1008 / sales dept. / 01.10.2000 11:18
...

One way to get this is the following:

storedprocedure1:
SELECT order_id, Max(datetime) As LastDateTime
FROM orders_report
GROUP BY order_id

storedprocedure2:
SELECT storedprocedure1.order_id, storedprocedure1.LastDateTime,
orders_reports.state
FROM orders_reports
INNER JOIN storedprocedure1
ON (orders_report.id = storedprocedure1.order_id)
AND (orders_report.datetime = storedprocedure1.lastdatetime);

storedprocedure3:
SELECT orders.id, storedprocedure2.state, storedprocedure2.lastdatetime
FROM storedprocedure2
RIGHT JOIN Auftraege
ON storedprocedure2.order_id = orders.id

Is there another way to do this? How can I optimize this way?

Thanks in advance and sorry for my bad english
Achim Habbel
Germany

2. external procedure problem

3. Query table vs query Stored procedures/views???

4. ado + access rights

5. I am attempting to execute a stored procedure as the sql query for a data

6. Help: Msg 613 error - procedure runs every other time! AAARRRGH!

7. Calling Stored procedure in View for a SELECT column

8. Web Companion Crashed FM - Unsolved problem in 5.5 !!!

9. temporary tables in stored procedures/parameter views vs stored procedures

10. Stored procedure dependancy on tables, views and other stored procedures

11. encapsulation of SELECT in views or stored procedures

12. Executing a Stored Procedure in a Stored Procedure and selecting on the result

13. return select values in stored procedure to a calling stored procedure