Intersection of NULLIF and ISNULL

The incident originated from the splicing of word fields, and the tragedy occurred due to the unclear nature of NULLIF.

1  1  Select  IsNull ( NullIf ( '' , dbo.f_CTRL_GetAlloy( ' 6063 ' , ' T5 ' )), ' 6063-T5 ' )
 2  2  Select  IsNull ( NullIf (dbo.f_CTRL_GetAlloy( ' 6063 ' , ' T5 ' ), '' ), ' 6063-T5 ' )
 3  
4 Function f_CTRL_GetAlloy Function explanation: When 6063 - T5 is passed in, it will return null; when other values ​​are passed in, it will return the field of the addition of two fields.

The above SQLs are processed in sequence by NULLIF/ISNULL, and the values ​​returned by the function f_CTRL_GetAlloy are all nulls, so NULLIF returns NULL at this time.

1  Select  NullIf ( '' , dbo.f_CTRL_GetAlloy( ' 6063 ' , ' T5 ' )) As NULLIF1
 2  Select  NullIf (dbo.f_CTRL_GetAlloy( ' 6063 ' , ' T5 ' ), '' ) As NULLIF2 Get two NULL values

The remaining SQL at this point

1  Select  IsNull ( Null , ' 6063-T5 ' )

As usual should get the value

1  6063 - T5

But actually get two values, SQL1/SQL2

1 1 Select NullIf('', dbo.f_CTRL_GetAlloy('6063', 'T5')) As NULLIF1 = 6
2 2 Select NullIf(dbo.f_CTRL_GetAlloy('6063', 'T5'), '') As NULLIF2 = '6063-T5'

It is initially believed that the result memory is paid at the same time as NUIFF is assigned.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324975713&siteId=291194637