469,625 Members | 1,146 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Querying data from multiple views

Hello,

I am relatively new to doing non-trivial SQL queries.

I have to get data out of 8 diff views based on a parameter Name.

There is a view having name-ssn pairs. All other views have SSN field.

For a person there MAY NOT be data in all the views.

I have to populate data into diff tables in a Report from different
views.

I would like to know what is the best way to approach it.

So far I was trying an Inner join from the Name-ssn vies to all other
views based on the SSN and test for the name field with the input
parameter.

I am thinking there will be problem of Cross join if I dont have data
in all views about a person.

Or the best way is to write query for each view and have all of them in
a stored procedure ?

Any help will be appreciated

Thanks
Bofo

Jul 23 '05 #1
1 1582
Win2003InstallIssues (bo******@yahoo.com) writes:
I am relatively new to doing non-trivial SQL queries.

I have to get data out of 8 diff views based on a parameter Name.

There is a view having name-ssn pairs. All other views have SSN field.

For a person there MAY NOT be data in all the views.

I have to populate data into diff tables in a Report from different
views.

I would like to know what is the best way to approach it.

So far I was trying an Inner join from the Name-ssn vies to all other
views based on the SSN and test for the name field with the input
parameter.

I am thinking there will be problem of Cross join if I dont have data
in all views about a person.

Or the best way is to write query for each view and have all of them in
a stored procedure ?


Your post is not that crystal clear. But it sounds to me that you
should left-join from the Name-SSN mapping view:

SELECT ...
FROM name_ssn_view n
LEFT JOIN ssn_view1 ON n.ssn = s1.ssn
LEFT JOIN ssn_view2 ON n.ssn = s2.ssn
...
WNERE n.name = @name

If this does not answer your question, please post some simplified
example that shows your setup.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Jerry Weinstein | last post: by
2 posts views Thread by Elliot Rodriguez | last post: by
4 posts views Thread by Alex | last post: by
6 posts views Thread by Greg | last post: by
3 posts views Thread by KemperR | last post: by
17 posts views Thread by stathis gotsis | last post: by
3 posts views Thread by ~john | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.