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 2005 Forums
 Transact-SQL (2005)
 Nested queries?

Author  Topic 

huvi
Starting Member

3 Posts

Posted - 2009-09-15 : 10:43:01
I have 3 views (PagaA, PagaB and PagaC)
and the 4th (PagaD) that is based on PagaA,PagaB and PagaC.
It works fine.
What I want now is the possibility to have the same view (like PagaD)
just using the select statement instead of the objects Paga PagaB and PagaC.
Is it possible?

thank's


PagaD:

SELECT PagaA.ID_Matricola, PagaA.Cognome, PagaA.Nome, PagaA.Data, PagaA.Cert_Medico, PagaA.TipoAttività,
PagaA.Attività, PagaA.ID_Att_Iscritto, PagaB.Totale, PagaB.TipoAttività AS Expr1, PagaB.Attività AS Expr2, PagaC.Quota,
PagaC.TipoAttività AS Expr3, PagaC.Attività AS Expr4

FROM PagaA LEFT OUTER JOIN
PagaC ON PagaA.ID_Matricola = PagaC.ID_Matricola LEFT OUTER JOIN
PagaB ON PagaA.ID_Att_Iscritto = PagaB.ID_Att_Iscritto

ORDER BY PagaA.TipoAttività, PagaA.Attività, PagaA.Cognome, PagaA.Nome

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-15 : 11:02:36
>>Is it possible?
Yes.

But rather than treat the underlying views as separate, nested, sub queries you may be able to write a single statement using just the underlying tables you need and returning just the columns you need.

Be One with the Optimizer
TG
Go to Top of Page

huvi
Starting Member

3 Posts

Posted - 2009-09-15 : 12:52:59
Thank you for the answer.

That's exactly what I want and what I'm trying ... but currently without success
Go to Top of Page

huvi
Starting Member

3 Posts

Posted - 2009-09-15 : 15:35:58
Ok.
I solved my problem as follow:

In PagaD I wrote between () instead of view PagaA (PagaB, PagaC) the sql statement of PagaA AS Table_A , instead of PagaB sql statement of PagaB AS TABLE_B)...

It works but I don't know if this is a good practice.

I've tried to write a single statement (without depending Tables) but no luck because I have to extract from 1 table 2 queries with complementary Filter conditions and append the resulting columns on a third table.

huvi





Go to Top of Page
   

- Advertisement -