question

Bhupendra99 avatar image
Bhupendra99 asked

Handle Null without Using Case

Hi I had a Table called Details which contains column Day1 with datatype as Int Now if the Column Day1 contains any number then I want to display 100 else if it contains null I want to display null only Apart from writing below case statement is there any more simpler way to do it Case when Day1=10 (Apart from 0 it can have any value including null) then 100 else Day1 I had around 31 columns I dont want to write case for each and every column please suggest what can be done
nullvalues
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Kev Riley avatar image
Kev Riley answered
Not sure I fully understand, but here's a way of 'not using a case' declare @Yourtable table (Day1 int) insert into @Yourtable select 1 insert into @Yourtable select 10 insert into @Yourtable select null insert into @Yourtable select null insert into @Yourtable select 5 select Day1, nullif(isnumeric(Day1),0)*100 from @Yourtable returns Day1 ----------- ----------- 1 100 10 100 NULL NULL NULL NULL 5 100 (5 row(s) affected) I wouldn't recommend doing this though - what's wrong with a case?
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks it worked
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.