事件源於字詞字段拼接,因爲不清楚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 函數f_CTRL_GetAlloy功能解釋:當6063-T5傳入時,返回空;其餘值傳入時,返回兩字段相加字段。
以上SQL都有NULLIF/ISNULL依次處理,函數f_CTRL_GetAlloy傳回值都爲空值,因此NULLIF此時返回的都爲NULL。spa
1 Select NullIf('', dbo.f_CTRL_GetAlloy('6063', 'T5')) As NULLIF1 2 Select NullIf(dbo.f_CTRL_GetAlloy('6063', 'T5'), '') As NULLIF2 獲得兩個NULL值
此時剩下的SQLcode
1 Select IsNull(Null, '6063-T5')
照常理應該獲得值blog
1 6063-T5
可是實際獲得兩個值,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'
初步認爲NUIFF賦值的同時付給告終果內存。內存