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!
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!