简体   繁体   中英

Difference between NULLIF(NULLIF(UPPER(T.Column),''),'NULL') and NULLIF(NULLIF(T.Column,''),'NULL')?

In my SQL I am using NULLIF(NULLIF(UPPER(T.Column),''),'NULL') at lof of places. But the problem is that it is updating T.Column to upper caps. Now I am thinking to use NULLIF(NULLIF(T.Column,''),'NULL') . My application is on production. Not sure running this can impact my query?

Will it impact your query...well it depends where you put all the NULLIF statements. You are giving the DB more work to do generally but if this column is included in a WHERE statement it will more than likely prevent the optimiser from using an index on your column. It therefore could impact on performance negatively. If its included in a select statement then it's impact will still be negative but much less.

Personally it looks a bit messy. If you are using it all over the place think about creating a view of this table. In the view create a column which has this logic in once. Your code can then reference the view instead without having to repeat the above functions. Your Stored Proc code will be a lot cleaner everywhere with the mess hidden!

If you are sure that all values in the field are uppercase, then the UPPER call is superflous.

Note that the value has to be upper case even if it contains the text 'NULL' , eg 'Null' or 'null' will not be converted to null , unless you have a case insensetive collation set on the field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM