SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 01/23/2013 :  16:55:47  Show Profile  Reply with Quote
Can Any one help me with belwo query.


UPDATE T1
SET T1.[Count] = 1.00/(SELECT COUNT(*) FROM [Tracker] T2 WHERE T1.[Application ID] = T2.[Application ID])
FROM [Tracker] T1


Actually in [Application ID] we ave some null values and getting the follwing error. Could you Please modify the query.

Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
The statement has been terminated.

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/23/2013 :  17:37:05  Show Profile  Reply with Quote


UPDATE T1
SET T1.[Count] = 1.00/ NULLIF ((SELECT COUNT(*) FROM [Tracker] T2 WHERE T1.[Application ID] = T2.[Application ID]),0)
FROM [Tracker] T1


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

422 Posts

Posted - 01/23/2013 :  17:40:55  Show Profile  Reply with Quote
quote:
Originally posted by jimf



UPDATE T1
SET T1.[Count] = 1.00/ NULLIF ((SELECT COUNT(*) FROM [Tracker] T2 WHERE T1.[Application ID] = T2.[Application ID]),0)
FROM [Tracker] T1


Jim

Everyday I learn something that somebody else already knew



Of course Jim meant:
UPDATE T1
SET T1.[Count] = 1.00/ NULLIF ((SELECT COUNT(*) FROM [Tracker] T2 WHERE T1.[Application ID] = T2.[Application ID]),1)
FROM [Tracker] T1
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/23/2013 :  17:46:30  Show Profile  Reply with Quote
No I didn't. NULLIF says if the 1st value = the 2nd value, return NULL. It's different than an isnull statement. Mine says "if the divisor = 0, return null instead"


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

422 Posts

Posted - 01/23/2013 :  18:06:30  Show Profile  Reply with Quote
quote:
Originally posted by jimf

No I didn't. NULLIF says if the 1st value = the 2nd value, return NULL. It's different than an isnull statement. Mine says "if the divisor = 0, return null instead"


Jim

Everyday I learn something that somebody else already knew


My mistake - sorry.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000