107
Answers

how to get distinct records sql server

Photo of Danish Habib

Danish Habib

9y
2.1k
1
If i have Two tables 
First
 QuestionID(primary key) Target value 
 1 100 
 Second table
 RecordID(primary key)    Achieved value QuestionID (FORIGN KEY)
 1 123 1
 2 432 1
When i want to calculate the sum using Inner join i.e.
SELECT SUM(TargetValue) AS TARGET ,SUM(AchievedValue) AS ACHIEVED FROM First
INNER JOIN Second AS S ONS.QuestionID=First.QuestionID 
Where 1=1
 
Then it gives me SUM OF TARGET VALUE 200 Instead of 100 Why??? 

Answers (107)

0
Photo of Deepak Tewatia
14 15.8k 23.6k 1y

It seems that you're encountering a System.NullReferenceException in your ASP.NET project. This type of exception typically occurs when you're trying to access a member (property, method, or field) of a reference type variable that is currently set to null. This means that the variable doesn't point to any object in memory.

To troubleshoot this issue, it's important to trace the code where the exception is being thrown. Look for the specific line or method that's causing the exception. Then, ensure that any objects or variables being accessed at that point are properly initialized and are not null.

Here's an example of how this error might occur:


// Assuming this is where the exception is occurring
MyClass myObject = null;
myObject.DoSomething(); // This line will throw a System.NullReferenceException

In this example, myObject is null, so calling the DoSomething method on it will result in a null reference exception.

To fix this issue, you need to ensure that myObject is properly initialized before calling any of its methods or accessing its properties.

If you could provide a code snippet or more context around where the exception is happening in your ASP.NET project, I may be able to offer more specific guidance.