Click here to Skip to main content
15,900,511 members
Home / Discussions / Database
   

Database

 
AnswerRe: trigger problem Pin
N a v a n e e t h18-Jan-09 21:44
N a v a n e e t h18-Jan-09 21:44 
QuestionPrimary key violation Pin
CodingYoshi16-Jan-09 18:35
CodingYoshi16-Jan-09 18:35 
AnswerRe: Primary key violation Pin
Aman Bhullar16-Jan-09 19:39
Aman Bhullar16-Jan-09 19:39 
AnswerRe: Primary key violation [modified] Pin
Wendelius16-Jan-09 22:12
mentorWendelius16-Jan-09 22:12 
QuestionDivision by zero error Pin
Unsy16-Jan-09 9:27
Unsy16-Jan-09 9:27 
AnswerRe: Division by zero error Pin
Wendelius16-Jan-09 9:28
mentorWendelius16-Jan-09 9:28 
GeneralRe: Division by zero error Pin
Unsy17-Jan-09 6:39
Unsy17-Jan-09 6:39 
GeneralRe: Division by zero error Pin
Wendelius17-Jan-09 7:11
mentorWendelius17-Jan-09 7:11 
Unsy wrote:
Please excuse the SQL code if it is full of errors as I am 250 miles from home


No problem.

And the problem was that the divisor is equal to zero in some cases. If it's zero, you wanted the result of the division to be zero. In that case you could for example use inline view for intermediate results and make the statement something like:
SELECT
    Field1
   ,Field2
   ,SUM( CASE Divisor
            WHEN 0 THEN 0
            ELSE Amount / Divisor
         END)
FROM (
   SELECT Field1,
          Field2,
          SUM(CASE 
                 WHEN Field3 IS NOT NULL OR Term - @WeeksPassed > 0 
                 THEN 0 
                 ELSE 1 
              END
          ) amount,
          SUM(CASE 
                 WHEN Field4 IS NOT NULL OR Term - @WeeksPassed > 0 
                 THEN 0 
                 ELSE 1 
              END
          ) divisor
   FROM
       Table1
   GROUP BY
       Field1
      ,Field2) alias
GROUP BY
    Field1
   ,Field2


The need to optimize rises from a bad design.My articles[^]

GeneralRe: Division by zero error Pin
Unsy18-Jan-09 21:37
Unsy18-Jan-09 21:37 
GeneralRe: Division by zero error Pin
Wendelius19-Jan-09 2:02
mentorWendelius19-Jan-09 2:02 
QuestionWalkthrough: Filtering and Updating in an N-Tier Data Applicaition Pin
Brian C Hart16-Jan-09 7:53
professionalBrian C Hart16-Jan-09 7:53 
QuestionI want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Aman786Singh16-Jan-09 7:04
Aman786Singh16-Jan-09 7:04 
AnswerRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Wendelius16-Jan-09 8:31
mentorWendelius16-Jan-09 8:31 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Aman786Singh16-Jan-09 20:26
Aman786Singh16-Jan-09 20:26 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Wendelius16-Jan-09 22:08
mentorWendelius16-Jan-09 22:08 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Aman786Singh17-Jan-09 7:18
Aman786Singh17-Jan-09 7:18 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Wendelius17-Jan-09 7:36
mentorWendelius17-Jan-09 7:36 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Aman786Singh17-Jan-09 7:51
Aman786Singh17-Jan-09 7:51 
GeneralRe: I want that whenever i perform any insertion,updation or deletion on a table,... same operation would be performed in another table located at different server . Pin
Wendelius17-Jan-09 7:53
mentorWendelius17-Jan-09 7:53 
QuestionCASE / LIKE code will not compile. Pin
dptalt16-Jan-09 7:00
dptalt16-Jan-09 7:00 
AnswerRe: CASE / LIKE code will not compile. Pin
Wendelius16-Jan-09 8:24
mentorWendelius16-Jan-09 8:24 
GeneralRe: CASE / LIKE code will not compile. Pin
dptalt19-Jan-09 3:15
dptalt19-Jan-09 3:15 
GeneralRe: CASE / LIKE code will not compile. Pin
Wendelius19-Jan-09 6:50
mentorWendelius19-Jan-09 6:50 
QuestionTSQL Case error Pin
dptalt16-Jan-09 6:56
dptalt16-Jan-09 6:56 
AnswerRe: TSQL Case error Pin
Wendelius16-Jan-09 8:08
mentorWendelius16-Jan-09 8:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.