I am attempting to use a user-defined function in the where clause of a query, but I am having a problem. With just one table, the query runs quickly. However, if I join two tables, the query runs until I cancel it or it times out. If I use the same function in the Select clause instead of the where clause, the query runs quickly with the two tables joined.
Runs until cancelled or times out:
Runs quickly:
My other option is to change my function to a stored procedure and use a cursor, but I had hoped to avoid that.
Does anyone have any ideas?
Thank you,
Andrea
Runs until cancelled or times out:
Code:
SELECT i.part_no, qty, description, dbo.PartType(i.part_no)
FROM inv_master i,
what_part w
WHERE i.part_no = w.part_no and
asm_no = 'K104081606' and
dbo.PartType(i.part_no) = 'Special Part'
Runs quickly:
Code:
SELECT i.part_no, qty, description, dbo.PartType(i.part_no)
FROM inv_master i,
what_part w
WHERE i.part_no = w.part_no and
asm_no = 'K104081606'
My other option is to change my function to a stored procedure and use a cursor, but I had hoped to avoid that.
Does anyone have any ideas?
Thank you,
Andrea