Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

How can i get the rows which is opposite side of another ?

$
0
0

I want to get the rows is opposite side of another depending on column value in the same 'JV_REF'

This is my example table 

----------------------------------

SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE dbo.Account (

JVID int NOT NULL IDENTITY PRIMARY KEY,
JV_REF nvarchar(10) ,
ACCOUNT_CODE nvarchar(10) ,
DEBIT decimal(10 , 2),
CREDIT decimal(10 , 2)

);

GO
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV001' , '01' , 100 , NULL );
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV001' , '02' , NULL , 100 );
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV002' , '01' , 100 , NULL );
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV002' , '03' , 50 , NULL);
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV002' , '02' , NULL , 150);
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV003' , '01' , 100 , NULL );
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV003' , '03' , 50 , NULL);
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV003' , '02' , NULL , 100);
INSERT INTO dbo.Account (JV_REF , ACCOUNT_CODE ,DEBIT  , CREDIT) VALUES ( 'JV003' , '04' , NULL , 50);

GO

SELECT * FROM dbo.Account  

DROP TABLE  dbo.Account;

--------------------------

Thanks


Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>