Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Dear,
Am writing a stored procedure and facing some problems.Plz help me out.

My Select Query is

SELECT LeftCount,RightCount FROM TM_Node WHERE Nodedate>=@PreDate and Nodedate<=@PostDate and AssociateId=@AssociateId

Where AssociateId is my PrimaryKey

Returning two rows.
The records of second row may be greater than the first one or remain same.

LeftCount RightCount
822 930
822 938

Diffleft = 822 - 822
DiffRight = 938 - 930

I want a query that will return me Diffleft as 0 and DiffRight as 8.
Posted
Updated 7-Jan-10 22:51pm
v2

Given that you've given one votes to the two people who tried to help you, and then rudely posted the same question again, I'm not sure why I'm still trying to help you. Now that I understand the question a bit better, the way to do this, would be to read the values into variables that you declare, then return their difference. Something like

declare @left1 int
declare @left2 int
declare @right1 int
declare @right2 int

Then

select @left1 = LeftCount, @right1 = RightCount FROM...

The hard part is, you need to figure out how to return left2 and right2 ( top 1 will return the first values ). Then you do

select @left2 - @left1 as DiffLeft, @right2 - @right1 as DiffRight
 
Share this answer
 
Hi U can use cursors for to perform this task.
 
Share this answer
 
wrote:
I want a query that will return me Diffleft as 0 and DiffRight as 8.


What do you mean ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900