Home Is this statement quicker than the previous?
Reply: 0

Is this statement quicker than the previous?

user10376
1#
user10376 Published in September 21, 2018, 8:15 am

I am running through some old code if I changed the logic of this CASE statement:

                CASE WHEN ClaimNo.ClaimNo IS NULL THEN '0'
                     WHEN ClaimNo.ClaimNo = 1 THEN '1'
                     WHEN ClaimNo.ClaimNo = 2 THEN '2'
                     WHEN ClaimNo.ClaimNo = 3 THEN '3'
                     WHEN ClaimNo.ClaimNo = 4 THEN '4'
                     ELSE '5+'
                END AS ClaimNo ,

If I changed it to:

                CASE WHEN ClaimNo.ClaimNo >= 5 THEN '5+'
                ELSE COALESCE(ClaimNo.ClaimNo,0) END 'ClaimNo' ,

Would the statement technically be quicker? Its obviously a lot shorter as a statement and appears that it wouldn't run as many statements to obtain the same result.

share|improve this question
  • Why don't you try? – HoneyBadger Feb 13 at 12:10
  • 2
    If you can find any real-world scenario where the difference would even matter (in terms of performance, not maintenance), I'll give you a prize. – Jeroen Mostert Feb 13 at 12:10
  • 7
    Second mixes strings with ints. First one does not give a chance for ClaimNo=0. I'd suggest to dig into accuracy first. – Ivan Starostin Feb 13 at 12:11
  • 1
    CASE expression, by the way. There are no CASE statements in T-SQL. – Larnu Feb 13 at 12:25
  • 1
    As pointed out in the accepted answer the second syntax is not valid. You should test syntax before asking which is faster. – paparazzo Feb 13 at 13:02

1 Answer 1

active oldest votes
up vote 10 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328839 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO