![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE FUNCTION fn_concat(@A varchar(255), @B varchar(255)) RETURNS varchar(255) AS BEGIN RETURN coalesce(@A,@B) END |
|
But why is the use of the function changing the behavior of the 2005 optimizer? |
#3
| |||
| |||
|
|
CREATE FUNCTION fn_concat(@A varchar(255), @B varchar(255)) RETURNS varchar(255) AS BEGIN RETURN coalesce(@A,@B) END This seems like a typical case of UDF abuse. Is there a real need for an UDF for such simple cases? Why not simply write your SQL statement as: |
|
SELECT A.a, COALESCE( A.b, A.c ) FROM A LEFT JOIN B ON A.id = B.id ; But why is the use of the function changing the behavior of the 2005 optimizer? The optimizer in SQL 2000 and SQL 2005 are different and this could be one of the processing differences due to an internal optimization routine called constant folding, which is pretty common in most modern DBMSs. |
![]() |
| Thread Tools | |
| Display Modes | |
| |