Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner SQL query - call one query from another?

Status
Not open for further replies.

eoinmag

Programmer
May 10, 2007
1
IE
Hi,

just starting to use SQL on sql server 2k and 2k5. I'm trying to decide the best way to do a query. Current system has one table with lots of details in it, I want to add the ability to have extra details in another seperate table. So, imagine if one record has an ID of 5555, I want to also have another table that *might* have extra details for ID 5555.

So I can think of a bunch of ways of doing this but I'd like advice on the most efficient way to do it. I imagine it would be a stored procedure that, half way through running, has an IF statement in it.

So it would go something like this:

I start a query on the first table for record 5555, half way through stored proc it has an IF statement that basically checks another table for an entry for a matching ID 5555, if the IF returns a 'true' (as in, there are records in the other table) then it returns them. If not, it continues as normal.


Thing is, I don't know if this is even possible with SQL. I could do it easily with two seperate queries and check through code, but this idea strikes me as more efficient.

Anyone got any tips / help on how to do that?

Thanks!
 
Have a look at LEFT OUTER JOIN.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top