Hi,
Plz, I need some info (SQL2000) :)
A stored procedure is like this:
"Select table1.id, table1.txt, (select table2.nr from table2 where
table2.fk_table1=table1.id) as nr where table1.id<>10"
The essence here is that "select table2.nr from table2 where
table2.fk_table1=table1.id" returns either the integer in table2.nr, or NULL
if there isnt a match. The whole sentence runs EXTREMELY slow...3-4 sec.
What is wrong?
"select table2.nr from table2 where table2.fk_table1=table1.id" runs quickly
outside the stored procedure. The original sentence without the "nr" (Select
table1.id, table1.txt where table1.id<>10) runs quickly too...
But together it slows down dramatically..why? I should mention that the
sub-query could return NULL if theres no match in table2...But i cant see
why that should slow things down (remember - it runs fine outside the SP)?
Thx,
PipHans
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11-09-2003