Q:

How can prevention of Divide by zero error encountered in sql server?

I'm new in sql server and write this query:
SELECT y.Telno,
         t.Cycle+'-'+y.Cycle Cycle,
        (((y.CurBill - t.CurBill)/t.CurBill)*100) Price FROM [ClubEatc].[dbo].[GetOnlineBills] y INNER JOIN
 [ClubEatc].[dbo].[GetOnlineBills] t
     ON y.Telno = t.TelNo AND CAST(y.Cycle as int)-1 = CAST(t.Cycle as int)

in table [GetOnlineBills] in field CurBill some place save zero,and the i get zero divid error,want when CurBill equals zero then just show 100% in result,how can i implant that?thanks all.

A:

Use NULLIF to handle Divide by zero error. 
Then use ISNULL to make the value as 100%
SELECT y.Telno,
       t.Cycle + '-' + y.Cycle                                                   Cycle,
       ( Isnull(( ( y.CurBill - t.CurBill ) / NULLIF(t.CurBill, 0) ), 1) * 100 ) Price
FROM   [ClubEatc].[dbo].[GetOnlineBills] y
       INNER JOIN [ClubEatc].[dbo].[GetOnlineBills] t
               ON y.Telno = t.TelNo
                  AND Cast(y.Cycle AS INT) - 1 = Cast(t.Cycle AS INT) 

