VB.net SQL Find the difference in two totals

Hi
I am using the following SQL query to calculate total scores in a SQL table for  Survey 1
Once the second survey is complete I have to calculate the difference between the scores.
I could calculate total survey 2 scores by changing the following to have Survey = 2
How do I calculate the difference, Do I use data tables?

            "Select [UserID],[Name],Sum([Gratitude]) as Sum_Gratitude, Sum([Reframing]) as Sum_Reframing, Sum([Empathy]) as Sum_Empathy, Sum([Adaptable]) as Sum_Adaptable, Sum([Teamwork]) As Sum_Teamwork From Diary2 Where CompanyID = 'ABC' And Survey = 1 Group By UserID, Name"
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harish VargheseProject LeaderCommented:
SELECT S1.UserId, S1.Name, 
	S1.Sum_Gratitude - S2.Sum_Gratitude as Sum_Gratitude_Diff,
	S1.Sum_Reframing - S2.Sum_Reframing as Sum_Reframing_Diff,
	S1.Sum_Empathy - S2.Sum_Empathy as Sum_Empathy_Diff,
	S1.Sum_Adaptable - S2.Sum_Adaptable as Sum_Adaptable_Diff,
	S1.Sum_Teamwork - S2.Sum_Teamwork as Sum_Teamwork_Diff
From 
	(Select [UserID], 
		[Name],
		Sum([Gratitude]) as Sum_Gratitude, 
		Sum([Reframing]) as Sum_Reframing, 
		Sum([Empathy]) as Sum_Empathy, 
		Sum([Adaptable]) as Sum_Adaptable, 
		Sum([Teamwork]) As Sum_Teamwork
	From Diary2 S1
	Where CompanyID = 'ABC' 
	And Survey = 1 
	Group By UserID, Name) S1,

	(Select [UserID], 
		[Name],
		Sum([Gratitude]) as Sum_Gratitude, 
		Sum([Reframing]) as Sum_Reframing, 
		Sum([Empathy]) as Sum_Empathy, 
		Sum([Adaptable]) as Sum_Adaptable, 
		Sum([Teamwork]) As Sum_Teamwork
	From Diary2 S1
	Where CompanyID = 'ABC' 
	And Survey = 2 
	Group By UserID, Name) S2
Where S1.UserId = S2.UserId

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for taking the time out to answer this. Much appreciated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.