Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
muzaffar_ali99
Starting Member
33 Posts |
Posted - 2006-04-14 : 05:19:33
|
| I have a problem that i am calculating percentage dividing by two fields a,bSelect a/b*100 from tblBut the problem i am facing is if b=0 my stored procedure gives error"Divide by zero error encountered."I want is if b=0 replace it with 1 using some function.Regards |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-14 : 05:31:07
|
| here are 2 different ways of doing it:declare @b int; set @b=0select coalesce(nullif(@b,0),1)select case when @b=0 then 1 else @b endrockmoose |
 |
|
|
muzaffar_ali99
Starting Member
33 Posts |
Posted - 2006-04-14 : 05:54:35
|
| Thanx It is working nicely. |
 |
|
|
|
|
|