0% found this document useful (0 votes)
18 views58 pages

GRN Orgi

Uploaded by

tripirio.meet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views58 pages

GRN Orgi

Uploaded by

tripirio.meet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 58

select (select Name from [O2I-O2 Power Pvt_ Ltd_- India$Company Information])

Company, h.[No_] as [GRN No],


h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor Name] [Vendor Name], h.
[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_], cast(l.Quantity as Numeric(35,2)) Quantity ,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost], cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced] ,l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)], cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[O2I-O2 Power Pvt_ Ltd_- India$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code Item],

(select distinct m.[Item Category Code] from dbo.[O2I-O2 Power Pvt_ Ltd_-
India$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[O2I-O2 Power Pvt_ Ltd_-
India$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],

cast((select sum(pl.Quantity) from dbo.[O2I-O2 Power Pvt_ Ltd_- India$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[O2I-O2 Power Pvt_ Ltd_-
India$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[O2I-O2 Power Pvt_ Ltd_- India$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[O2I-O2 Power Pvt_ Ltd_-
India$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [O2I-O2 Power Pvt_ Ltd_- India$Detailed GST
Ledger Entry] g inner join [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [O2I-O2 Power Pvt_ Ltd_- India$Detailed GST
Ledger Entry] g inner join [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [O2I-O2 Power Pvt_ Ltd_- India$Detailed GST
Ledger Entry] g inner join [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [O2I-O2 Power Pvt_ Ltd_- India$Detailed GST
Ledger Entry] g inner join [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [O2I-O2 Power Pvt_ Ltd_- India$Detailed
GST Ledger Entry] g inner join [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [O2I-O2 Power Pvt_ Ltd_- India$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount],
(select distinct Top 1 pl.[Document No_] from [O2I-O2 Power Pvt_ Ltd_-
India$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[O2I-O2 Power Pvt_ Ltd_- India$Purch_ Rcpt_ Header] h inner join dbo.[O2I-
O2 Power Pvt_ Ltd_- India$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[O2I-O2 Power Pvt_ Ltd_- India$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [GLO-Glowsun Powergen Pvt_ Ltd_$Company Information])
Company, h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity, cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[GLO-Glowsun Powergen Pvt_ Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[GLO-Glowsun Powergen Pvt_
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[GLO-Glowsun Powergen Pvt_


Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[GLO-Glowsun Powergen Pvt_ Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[GLO-Glowsun Powergen Pvt_
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[GLO-Glowsun Powergen Pvt_ Ltd_$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[GLO-Glowsun Powergen Pvt_
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [GLO-Glowsun Powergen Pvt_ Ltd_$Detailed GST
Ledger Entry] g inner join [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [GLO-Glowsun Powergen Pvt_ Ltd_$Detailed GST


Ledger Entry] g inner join [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [GLO-Glowsun Powergen Pvt_ Ltd_$Detailed GST


Ledger Entry] g inner join [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [GLO-Glowsun Powergen Pvt_ Ltd_$Detailed GST


Ledger Entry] g inner join [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [GLO-Glowsun Powergen Pvt_ Ltd_$Detailed
GST Ledger Entry] g inner join [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount],
(select distinct Top 1 pl.[Document No_] from [GLO-Glowsun Powergen Pvt_
Ltd_$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Rcpt_ Header] h inner join dbo.
[GLO-Glowsun Powergen Pvt_ Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[GLO-Glowsun Powergen Pvt_ Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [CYC-Cyclic Energy Pwr Pvt Ltd_$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[CYC-Cyclic Energy Pwr Pvt Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[CYC-Cyclic Energy Pwr Pvt
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[CYC-Cyclic Energy Pwr Pvt
Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[CYC-Cyclic Energy Pwr Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[CYC-Cyclic Energy Pwr Pvt
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[CYC-Cyclic Energy Pwr Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[CYC-Cyclic Energy Pwr Pvt
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [CYC-Cyclic Energy Pwr Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [CYC-Cyclic Energy Pwr Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [CYC-Cyclic Energy Pwr Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [CYC-Cyclic Energy Pwr Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [CYC-Cyclic Energy Pwr Pvt Ltd_$Detailed
GST Ledger Entry] g inner join [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [CYC-Cyclic Energy Pwr Pvt
Ltd_$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Rcpt_ Header] h inner join dbo.
[CYC-Cyclic Energy Pwr Pvt Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[CYC-Cyclic Energy Pwr Pvt Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [CSP-Clean Solar Pwr-Bhainsada)$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[CSP-Clean Solar Pwr-Bhainsada)$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[CSP-Clean Solar Pwr-Bhainsada)
$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[CSP-Clean Solar Pwr-Bhainsada)


$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[CSP-Clean Solar Pwr-Bhainsada)$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[CSP-Clean Solar Pwr-Bhainsada)
$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order
Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[CSP-Clean Solar Pwr-Bhainsada)$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[CSP-Clean Solar Pwr-
Bhainsada)$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [CSP-Clean Solar Pwr-Bhainsada)$Detailed GST
Ledger Entry] g inner join [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [CSP-Clean Solar Pwr-Bhainsada)$Detailed GST


Ledger Entry] g inner join [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [CSP-Clean Solar Pwr-Bhainsada)$Detailed GST


Ledger Entry] g inner join [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [CSP-Clean Solar Pwr-Bhainsada)$Detailed GST


Ledger Entry] g inner join [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [CSP-Clean Solar Pwr-Bhainsada)$Detailed
GST Ledger Entry] g inner join [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [CSP-Clean Solar Pwr-Bhainsada)$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [CSP-Clean Solar Pwr-Bhainsada)
$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line
No_]=l.[Line No_]) [PI No]

from dbo.[CSP-Clean Solar Pwr-Bhainsada)$Purch_ Rcpt_ Header] h inner join dbo.


[CSP-Clean Solar Pwr-Bhainsada)$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[CSP-Clean Solar Pwr-Bhainsada)$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ALT-Altra Xergi Power Pvt Ltd_$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ALT-Altra Xergi Power Pvt Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ALT-Altra Xergi Power Pvt
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ALT-Altra Xergi Power Pvt
Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ALT-Altra Xergi Power Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ALT-Altra Xergi Power Pvt
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[ALT-Altra Xergi Power Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[ALT-Altra Xergi Power Pvt
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ALT-Altra Xergi Power Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ALT-Altra Xergi Power Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ALT-Altra Xergi Power Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ALT-Altra Xergi Power Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ALT-Altra Xergi Power Pvt Ltd_$Detailed
GST Ledger Entry] g inner join [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ALT-Altra Xergi Power Pvt Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ALT-Altra Xergi Power Pvt
Ltd_$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[ALT-Altra Xergi Power Pvt Ltd_$Purch_ Rcpt_ Header] h inner join dbo.
[ALT-Altra Xergi Power Pvt Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ALT-Altra Xergi Power Pvt Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [XLX-XL Xergi Power Pv_ Ltd_$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[XLX-XL Xergi Power Pv_ Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[XLX-XL Xergi Power Pv_
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[XLX-XL Xergi Power Pv_
Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[XLX-XL Xergi Power Pv_ Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[XLX-XL Xergi Power Pv_
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[XLX-XL Xergi Power Pv_ Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[XLX-XL Xergi Power Pv_
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [XLX-XL Xergi Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [XLX-XL Xergi Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [XLX-XL Xergi Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [XLX-XL Xergi Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [XLX-XL Xergi Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [XLX-XL Xergi Power Pv_ Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [XLX-XL Xergi Power Pv_ Ltd_$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[XLX-XL Xergi Power Pv_ Ltd_$Purch_ Rcpt_ Header] h inner join dbo.[XLX-
XL Xergi Power Pv_ Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[XLX-XL Xergi Power Pv_ Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [TEQ-Teq Green Power Pv_ Ltd_$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[TEQ-Teq Green Power Pv_ Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[TEQ-Teq Green Power Pv_
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],
(select distinct m.[Product Group Code] from dbo.[TEQ-Teq Green Power Pv_
Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[TEQ-Teq Green Power Pv_ Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[TEQ-Teq Green Power Pv_
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[TEQ-Teq Green Power Pv_ Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[TEQ-Teq Green Power Pv_
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [TEQ-Teq Green Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [TEQ-Teq Green Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [TEQ-Teq Green Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [TEQ-Teq Green Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [TEQ-Teq Green Power Pv_ Ltd_$Detailed GST
Ledger Entry] g inner join [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [TEQ-Teq Green Power Pv_ Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [TEQ-Teq Green Power Pv_
Ltd_$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]
from dbo.[TEQ-Teq Green Power Pv_ Ltd_$Purch_ Rcpt_ Header] h inner join dbo.[TEQ-
Teq Green Power Pv_ Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[TEQ-Teq Green Power Pv_ Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [SOL-Solalite Power Private Ltd$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[SOL-Solalite Power Private Ltd$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[SOL-Solalite Power Private
Ltd$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[SOL-Solalite Power Private


Ltd$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[SOL-Solalite Power Private Ltd$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[SOL-Solalite Power Private
Ltd$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value],

(select distinct [HSN_SAC Code] from dbo.[SOL-Solalite Power Private Ltd$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[SOL-Solalite Power Private
Ltd$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST
Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [SOL-Solalite Power Private Ltd$Detailed
GST Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [SOL-Solalite Power Private Ltd$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [SOL-Solalite Power Private
Ltd$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[SOL-Solalite Power Private Ltd$Purch_ Rcpt_ Header] h inner join dbo.
[SOL-Solalite Power Private Ltd$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[SOL-Solalite Power Private Ltd$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ENE-Energizent Power Pvt Ltd_$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ENE-Energizent Power Pvt Ltd_$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ENE-Energizent Power Pvt
Ltd_$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ENE-Energizent Power Pvt


Ltd_$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ENE-Energizent Power Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ENE-Energizent Power Pvt
Ltd_$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[ENE-Energizent Power Pvt Ltd_$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[ENE-Energizent Power Pvt
Ltd_$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ENE-Energizent Power Pvt Ltd_$Detailed GST
Ledger Entry] g inner join [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ENE-Energizent Power Pvt Ltd_$Detailed GST


Ledger Entry] g inner join [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ENE-Energizent Power Pvt Ltd_$Detailed GST


Ledger Entry] g inner join [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ENE-Energizent Power Pvt Ltd_$Detailed GST


Ledger Entry] g inner join [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ENE-Energizent Power Pvt Ltd_$Detailed
GST Ledger Entry] g inner join [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ENE-Energizent Power Pvt Ltd_$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ENE-Energizent Power Pvt
Ltd_$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[ENE-Energizent Power Pvt Ltd_$Purch_ Rcpt_ Header] h inner join dbo.[ENE-
Energizent Power Pvt Ltd_$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ENE-Energizent Power Pvt Ltd_$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [BEP-Beempow Energy Private Ltd$Company Information])
Company, h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[BEP-Beempow Energy Private Ltd$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[BEP-Beempow Energy Private
Ltd$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[BEP-Beempow Energy Private


Ltd$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[BEP-Beempow Energy Private Ltd$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[BEP-Beempow Energy Private
Ltd$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[BEP-Beempow Energy Private Ltd$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[BEP-Beempow Energy Private
Ltd$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [BEP-Beempow Energy Private Ltd$Detailed GST
Ledger Entry] g inner join [BEP-Beempow Energy Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [BEP-Beempow Energy Private Ltd$Detailed GST


Ledger Entry] g inner join [BEP-Beempow Energy Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [BEP-Beempow Energy Private Ltd$Detailed GST


Ledger Entry] g inner join [BEP-Beempow Energy Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [BEP-Beempow Energy Private Ltd$Detailed GST


Ledger Entry] g inner join [BEP-Beempow Energy Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [BEP-Beempow Energy Private Ltd$Detailed
GST Ledger Entry] g inner join [BEP-Beempow Energy Private Ltd$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [BEP-Beempow Energy Private Ltd$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [BEP-Beempow Energy Private
Ltd$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[BEP-Beempow Energy Private Ltd$Purch_ Rcpt_ Header] h inner join dbo.
[BEP-Beempow Energy Private Ltd$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[BEP-Beempow Energy Private Ltd$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [TXI-TEQ GREEN POWER XI PVT LTD$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[TXI-TEQ GREEN POWER XI PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[TXI-TEQ GREEN POWER XI PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[TXI-TEQ GREEN POWER XI PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[TXI-TEQ GREEN POWER XI PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[TXI-TEQ GREEN POWER XI PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[TXI-TEQ GREEN POWER XI PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[TXI-TEQ GREEN POWER XI PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [TXI-TEQ GREEN POWER XI PVT LTD$Detailed GST
Ledger Entry] g inner join [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [TXI-TEQ GREEN POWER XI PVT LTD$Detailed GST
Ledger Entry] g inner join [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [TXI-TEQ GREEN POWER XI PVT LTD$Detailed GST
Ledger Entry] g inner join [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [TXI-TEQ GREEN POWER XI PVT LTD$Detailed GST
Ledger Entry] g inner join [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [TXI-TEQ GREEN POWER XI PVT LTD$Detailed
GST Ledger Entry] g inner join [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [TXI-TEQ GREEN POWER XI PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.
[TXI-TEQ GREEN POWER XI PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[TXI-TEQ GREEN POWER XI PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [TGX-TEQ GREEN POWER X PVT LTD$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[TGX-TEQ GREEN POWER X PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code Item],
(select distinct m.[Item Category Code] from dbo.[TGX-TEQ GREEN POWER X PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[TGX-TEQ GREEN POWER X PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],

cast((select sum(pl.Quantity) from dbo.[TGX-TEQ GREEN POWER X PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[TGX-TEQ GREEN POWER X PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,
(select distinct [HSN_SAC Code] from dbo.[TGX-TEQ GREEN POWER X PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],

(select distinct top 1 [GST Registration No_] from dbo.[TGX-TEQ GREEN POWER X PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [TGX-TEQ GREEN POWER X PVT LTD$Detailed GST
Ledger Entry] g inner join [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [TGX-TEQ GREEN POWER X PVT LTD$Detailed GST
Ledger Entry] g inner join [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [TGX-TEQ GREEN POWER X PVT LTD$Detailed GST
Ledger Entry] g inner join [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [TGX-TEQ GREEN POWER X PVT LTD$Detailed GST
Ledger Entry] g inner join [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [TGX-TEQ GREEN POWER X PVT LTD$Detailed
GST Ledger Entry] g inner join [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [TGX-TEQ GREEN POWER X PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [TGX-TEQ GREEN POWER X PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]
from dbo.[TGX-TEQ GREEN POWER X PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[TGX-
TEQ GREEN POWER X PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[TGX-TEQ GREEN POWER X PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [TG9-TEQ GREEN POWER IX PVT LTD$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[TG9-TEQ GREEN POWER IX PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[TG9-TEQ GREEN POWER IX PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[TG9-TEQ GREEN POWER IX PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[TG9-TEQ GREEN POWER IX PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[TG9-TEQ GREEN POWER IX PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[TG9-TEQ GREEN POWER IX PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[TG9-TEQ GREEN POWER IX PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [TG9-TEQ GREEN POWER IX PVT LTD$Detailed GST
Ledger Entry] g inner join [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],
cast((select sum([GST Amount]) from [TG9-TEQ GREEN POWER IX PVT LTD$Detailed GST
Ledger Entry] g inner join [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [TG9-TEQ GREEN POWER IX PVT LTD$Detailed GST
Ledger Entry] g inner join [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [TG9-TEQ GREEN POWER IX PVT LTD$Detailed GST
Ledger Entry] g inner join [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [TG9-TEQ GREEN POWER IX PVT LTD$Detailed
GST Ledger Entry] g inner join [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [TG9-TEQ GREEN POWER IX PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.
[TG9-TEQ GREEN POWER IX PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[TG9-TEQ GREEN POWER IX PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ESE-ES ENERGY PRIVATE LIMITED$Company Information])
Company, h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESE-ES ENERGY PRIVATE LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESE-ES ENERGY PRIVATE
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESE-ES ENERGY PRIVATE


LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESE-ES ENERGY PRIVATE LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESE-ES ENERGY PRIVATE
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESE-ES ENERGY PRIVATE LIMITED$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESE-ES ENERGY PRIVATE
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESE-ES ENERGY PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ESE-ES ENERGY PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESE-ES ENERGY PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESE-ES ENERGY PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESE-ES ENERGY PRIVATE LIMITED$Detailed
GST Ledger Entry] g inner join [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESE-ES ENERGY PRIVATE LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESE-ES ENERGY PRIVATE
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESE-ES ENERGY PRIVATE LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESE-
ES ENERGY PRIVATE LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESE-ES ENERGY PRIVATE LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ESP-ES SUN POWER PVT LIMITED$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESP-ES SUN POWER PVT LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESP-ES SUN POWER PVT
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESP-ES SUN POWER PVT
LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESP-ES SUN POWER PVT LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESP-ES SUN POWER PVT
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESP-ES SUN POWER PVT LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESP-ES SUN POWER PVT
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESP-ES SUN POWER PVT LIMITED$Detailed GST
Ledger Entry] g inner join [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ESP-ES SUN POWER PVT LIMITED$Detailed GST
Ledger Entry] g inner join [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESP-ES SUN POWER PVT LIMITED$Detailed GST
Ledger Entry] g inner join [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESP-ES SUN POWER PVT LIMITED$Detailed GST
Ledger Entry] g inner join [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESP-ES SUN POWER PVT LIMITED$Detailed GST
Ledger Entry] g inner join [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESP-ES SUN POWER PVT LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESP-ES SUN POWER PVT
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESP-ES SUN POWER PVT LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESP-
ES SUN POWER PVT LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESP-ES SUN POWER PVT LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ESS-ES SOLAR PRIVATE LIMITED$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESS-ES SOLAR PRIVATE


LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESS-ES SOLAR PRIVATE
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESS-
ES SOLAR PRIVATE LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [DRE-DRES ENERGY PVT LTD$Company Information]) Company,h.
[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor Name]
[Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[DRE-DRES ENERGY PVT LTD$Item] m where m.
[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[DRE-DRES ENERGY PVT LTD$Item] m
where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[DRE-DRES ENERGY PVT LTD$Item] m
where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[DRE-DRES ENERGY PVT LTD$Purchase Line] pl
where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]) as
NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[DRE-DRES ENERGY PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[DRE-DRES ENERGY PVT LTD$Purchase Line]
pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_] ) [PO
HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[DRE-DRES ENERGY PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [DRE-DRES ENERGY PVT LTD$Detailed GST Ledger
Entry] g inner join [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [DRE-DRES ENERGY PVT LTD$Detailed GST Ledger
Entry] g inner join [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [DRE-DRES ENERGY PVT LTD$Detailed GST Ledger
Entry] g inner join [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [DRE-DRES ENERGY PVT LTD$Detailed GST Ledger
Entry] g inner join [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [DRE-DRES ENERGY PVT LTD$Detailed GST
Ledger Entry] g inner join [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [DRE-DRES ENERGY PVT LTD$Purch_ Inv_ Line] pl
where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [DRE-DRES ENERGY PVT LTD$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[DRE-DRES ENERGY PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[DRE-DRES
ENERGY PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[DRE-DRES ENERGY PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.[Document
No_]

UNION ALL
select (select Name from [ESS-ES SOLAR PRIVATE LIMITED$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESS-ES SOLAR PRIVATE


LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESS-ES SOLAR PRIVATE
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESS-
ES SOLAR PRIVATE LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [SOL-Solalite Power Private Ltd$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[SOL-Solalite Power Private Ltd$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[SOL-Solalite Power Private
Ltd$Item] m where m.[No_]=l.[No_] ) [Item Category Code],
(select distinct m.[Product Group Code] from dbo.[SOL-Solalite Power Private
Ltd$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[SOL-Solalite Power Private Ltd$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[SOL-Solalite Power Private
Ltd$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[SOL-Solalite Power Private Ltd$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[SOL-Solalite Power Private
Ltd$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST
Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [SOL-Solalite Power Private Ltd$Detailed GST


Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [SOL-Solalite Power Private Ltd$Detailed
GST Ledger Entry] g inner join [SOL-Solalite Power Private Ltd$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [SOL-Solalite Power Private Ltd$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [SOL-Solalite Power Private
Ltd$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]
from dbo.[SOL-Solalite Power Private Ltd$Purch_ Rcpt_ Header] h inner join dbo.
[SOL-Solalite Power Private Ltd$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[SOL-Solalite Power Private Ltd$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ESS-ES SOLAR PRIVATE LIMITED$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESS-ES SOLAR PRIVATE


LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],
cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESS-ES SOLAR PRIVATE
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESS-
ES SOLAR PRIVATE LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [OR1-O2 RENEWABLE E I PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR1-O2 RENEWABLE E I PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR1-O2 RENEWABLE E I PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR1-O2 RENEWABLE E I PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR1-O2 RENEWABLE E I PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR1-O2 RENEWABLE E I PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR1-O2 RENEWABLE E I PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR1-O2 RENEWABLE E I PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR1-O2 RENEWABLE E I PVT LTD$Detailed GST
Ledger Entry] g inner join [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR1-O2 RENEWABLE E I PVT LTD$Detailed GST


Ledger Entry] g inner join [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR1-O2 RENEWABLE E I PVT LTD$Detailed GST


Ledger Entry] g inner join [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR1-O2 RENEWABLE E I PVT LTD$Detailed GST


Ledger Entry] g inner join [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR1-O2 RENEWABLE E I PVT LTD$Detailed GST
Ledger Entry] g inner join [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR1-O2 RENEWABLE E I PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR1-O2 RENEWABLE E I PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[OR1-O2 RENEWABLE E I PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[OR1-
O2 RENEWABLE E I PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR1-O2 RENEWABLE E I PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL
select (select Name from [ESS-ES SOLAR PRIVATE LIMITED$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[ESS-ES SOLAR PRIVATE


LIMITED$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line
No_]=l.[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[ESS-ES SOLAR PRIVATE
LIMITED$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST


Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [ESS-ES SOLAR PRIVATE LIMITED$Detailed GST
Ledger Entry] g inner join [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [ESS-ES SOLAR PRIVATE LIMITED$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [ESS-ES SOLAR PRIVATE
LIMITED$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.
[Receipt Line No_]=l.[Line No_]) [PI No]

from dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Header] h inner join dbo.[ESS-
ES SOLAR PRIVATE LIMITED$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[ESS-ES SOLAR PRIVATE LIMITED$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [OR2-O2 RENEWABLE E II PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR2-O2 RENEWABLE E II PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR2-O2 RENEWABLE E II PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR2-O2 RENEWABLE E II PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR2-O2 RENEWABLE E II PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR2-O2 RENEWABLE E II PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR2-O2 RENEWABLE E II PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR2-O2 RENEWABLE E II PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR2-O2 RENEWABLE E II PVT LTD$Detailed GST
Ledger Entry] g inner join [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR2-O2 RENEWABLE E II PVT LTD$Detailed GST


Ledger Entry] g inner join [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR2-O2 RENEWABLE E II PVT LTD$Detailed GST


Ledger Entry] g inner join [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR2-O2 RENEWABLE E II PVT LTD$Detailed GST


Ledger Entry] g inner join [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR2-O2 RENEWABLE E II PVT LTD$Detailed
GST Ledger Entry] g inner join [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR2-O2 RENEWABLE E II PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR2-O2 RENEWABLE E II PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[OR2-O2 RENEWABLE E II PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[OR2-
O2 RENEWABLE E II PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR2-O2 RENEWABLE E II PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [OR3-O2RENEWABLE E III PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR3-O2RENEWABLE E III PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR3-O2RENEWABLE E III PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR3-O2RENEWABLE E III PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR3-O2RENEWABLE E III PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR3-O2RENEWABLE E III PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR3-O2RENEWABLE E III PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR3-O2RENEWABLE E III PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR3-O2RENEWABLE E III PVT LTD$Detailed GST
Ledger Entry] g inner join [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR3-O2RENEWABLE E III PVT LTD$Detailed GST


Ledger Entry] g inner join [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR3-O2RENEWABLE E III PVT LTD$Detailed GST


Ledger Entry] g inner join [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR3-O2RENEWABLE E III PVT LTD$Detailed GST


Ledger Entry] g inner join [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR3-O2RENEWABLE E III PVT LTD$Detailed
GST Ledger Entry] g inner join [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR3-O2RENEWABLE E III PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR3-O2RENEWABLE E III PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[OR3-O2RENEWABLE E III PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[OR3-
O2RENEWABLE E III PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR3-O2RENEWABLE E III PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [OR4-O2RENEWABLE ENE IV PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR4-O2RENEWABLE ENE IV PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR4-O2RENEWABLE ENE IV PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR4-O2RENEWABLE ENE IV PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR4-O2RENEWABLE ENE IV PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR4-O2RENEWABLE ENE IV PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR4-O2RENEWABLE ENE IV PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR4-O2RENEWABLE ENE IV PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR4-O2RENEWABLE ENE IV PVT LTD$Detailed GST
Ledger Entry] g inner join [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR4-O2RENEWABLE ENE IV PVT LTD$Detailed GST


Ledger Entry] g inner join [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR4-O2RENEWABLE ENE IV PVT LTD$Detailed GST


Ledger Entry] g inner join [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR4-O2RENEWABLE ENE IV PVT LTD$Detailed GST


Ledger Entry] g inner join [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR4-O2RENEWABLE ENE IV PVT LTD$Detailed
GST Ledger Entry] g inner join [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR4-O2RENEWABLE ENE IV PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.
[OR4-O2RENEWABLE ENE IV PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR4-O2RENEWABLE ENE IV PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [OR5-O2RENEWABLE E V PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR5-O2RENEWABLE E V PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR5-O2RENEWABLE E V PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR5-O2RENEWABLE E V PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR5-O2RENEWABLE E V PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR5-O2RENEWABLE E V PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR5-O2RENEWABLE E V PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR5-O2RENEWABLE E V PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR5-O2RENEWABLE E V PVT LTD$Detailed GST
Ledger Entry] g inner join [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR5-O2RENEWABLE E V PVT LTD$Detailed GST


Ledger Entry] g inner join [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR5-O2RENEWABLE E V PVT LTD$Detailed GST


Ledger Entry] g inner join [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR5-O2RENEWABLE E V PVT LTD$Detailed GST


Ledger Entry] g inner join [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR5-O2RENEWABLE E V PVT LTD$Detailed GST
Ledger Entry] g inner join [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR5-O2RENEWABLE E V PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR5-O2RENEWABLE E V PVT LTD$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[OR5-O2RENEWABLE E V PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[OR5-


O2RENEWABLE E V PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR5-O2RENEWABLE E V PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [TX2-TEQ GREEN PWR XII PVT LTD$Company Information])
Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[TX2-TEQ GREEN PWR XII PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[TX2-TEQ GREEN PWR XII PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[TX2-TEQ GREEN PWR XII PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[TX2-TEQ GREEN PWR XII PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[TX2-TEQ GREEN PWR XII PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[TX2-TEQ GREEN PWR XII PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[TX2-TEQ GREEN PWR XII PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [TX2-TEQ GREEN PWR XII PVT LTD$Detailed GST
Ledger Entry] g inner join [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [TX2-TEQ GREEN PWR XII PVT LTD$Detailed GST
Ledger Entry] g inner join [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [TX2-TEQ GREEN PWR XII PVT LTD$Detailed GST
Ledger Entry] g inner join [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [TX2-TEQ GREEN PWR XII PVT LTD$Detailed GST
Ledger Entry] g inner join [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [TX2-TEQ GREEN PWR XII PVT LTD$Detailed
GST Ledger Entry] g inner join [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [TX2-TEQ GREEN PWR XII PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[TX2-
TEQ GREEN PWR XII PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[TX2-TEQ GREEN PWR XII PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [PWG-PANAMA WIND E G PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[PWG-PANAMA WIND E G PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[PWG-PANAMA WIND E G PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[PWG-PANAMA WIND E G PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[PWG-PANAMA WIND E G PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[PWG-PANAMA WIND E G PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[PWG-PANAMA WIND E G PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[PWG-PANAMA WIND E G PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [PWG-PANAMA WIND E G PVT LTD$Detailed GST
Ledger Entry] g inner join [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [PWG-PANAMA WIND E G PVT LTD$Detailed GST


Ledger Entry] g inner join [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [PWG-PANAMA WIND E G PVT LTD$Detailed GST


Ledger Entry] g inner join [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [PWG-PANAMA WIND E G PVT LTD$Detailed GST


Ledger Entry] g inner join [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [PWG-PANAMA WIND E G PVT LTD$Detailed GST
Ledger Entry] g inner join [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [PWG-PANAMA WIND E G PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [PWG-PANAMA WIND E G PVT LTD$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[PWG-PANAMA WIND E G PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[PWG-
PANAMA WIND E G PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[PWG-PANAMA WIND E G PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]
UNION ALL

select (select Name from [PWS-PANAMA WIND E S PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[PWS-PANAMA WIND E S PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[PWS-PANAMA WIND E S PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[PWS-PANAMA WIND E S PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[PWS-PANAMA WIND E S PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[PWS-PANAMA WIND E S PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[PWS-PANAMA WIND E S PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[PWS-PANAMA WIND E S PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [PWS-PANAMA WIND E S PVT LTD$Detailed GST
Ledger Entry] g inner join [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [PWS-PANAMA WIND E S PVT LTD$Detailed GST


Ledger Entry] g inner join [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [PWS-PANAMA WIND E S PVT LTD$Detailed GST


Ledger Entry] g inner join [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [PWS-PANAMA WIND E S PVT LTD$Detailed GST


Ledger Entry] g inner join [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [PWS-PANAMA WIND E S PVT LTD$Detailed GST
Ledger Entry] g inner join [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [PWS-PANAMA WIND E S PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [PWS-PANAMA WIND E S PVT LTD$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[PWS-PANAMA WIND E S PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[PWS-
PANAMA WIND E S PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[PWS-PANAMA WIND E S PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [InterComp_UAT Setup SPV$Company Information]) Company,h.


[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor Name]
[Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[InterComp_UAT Setup SPV$Item] m where m.
[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[InterComp_UAT Setup SPV$Item] m
where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[InterComp_UAT Setup SPV$Item] m


where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[InterComp_UAT Setup SPV$Purchase Line] pl
where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]) as
NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[InterComp_UAT Setup
SPV$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[InterComp_UAT Setup SPV$Purchase Line]


pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_] ) [PO
HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[InterComp_UAT Setup
SPV$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [InterComp_UAT Setup SPV$Detailed GST Ledger
Entry] g inner join [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [InterComp_UAT Setup SPV$Detailed GST Ledger


Entry] g inner join [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [InterComp_UAT Setup SPV$Detailed GST Ledger


Entry] g inner join [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [InterComp_UAT Setup SPV$Detailed GST Ledger


Entry] g inner join [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [InterComp_UAT Setup SPV$Detailed GST
Ledger Entry] g inner join [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [InterComp_UAT Setup SPV$Purch_ Inv_ Line] pl
where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [InterComp_UAT Setup SPV$Purch_
Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.
[Line No_]) [PI No]

from dbo.[InterComp_UAT Setup SPV$Purch_ Rcpt_ Header] h inner join dbo.


[InterComp_UAT Setup SPV$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[InterComp_UAT Setup SPV$Purch_ Rcpt_ Line] l on h.No_=l.[Document
No_]

UNION ALL

select (select Name from [InterComp_UATManco$Company Information]) Company,h.[No_]


as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor Name] [Vendor
Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[InterComp_UATManco$Item] m where m.
[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[InterComp_UATManco$Item] m where
m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[InterComp_UATManco$Item] m where


m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[InterComp_UATManco$Purchase Line] pl
where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]) as
NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[InterComp_UATManco$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[InterComp_UATManco$Purchase Line] pl


where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_] ) [PO
HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[InterComp_UATManco$Vendor]
v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [InterComp_UATManco$Detailed GST Ledger Entry]
g inner join [InterComp_UATManco$Purch_ Inv_ Line] pl on g.[Document No_]=pl.
[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [InterComp_UATManco$Detailed GST Ledger Entry]


g inner join [InterComp_UATManco$Purch_ Inv_ Line] pl on g.[Document No_]=pl.
[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [InterComp_UATManco$Detailed GST Ledger Entry]


g inner join [InterComp_UATManco$Purch_ Inv_ Line] pl on g.[Document No_]=pl.
[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [InterComp_UATManco$Detailed GST Ledger Entry]


g inner join [InterComp_UATManco$Purch_ Inv_ Line] pl on g.[Document No_]=pl.
[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [InterComp_UATManco$Detailed GST Ledger
Entry] g inner join [InterComp_UATManco$Purch_ Inv_ Line] pl on g.[Document
No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [InterComp_UATManco$Purch_ Inv_ Line] pl
where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [InterComp_UATManco$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) [PI No]

from dbo.[InterComp_UATManco$Purch_ Rcpt_ Header] h inner join dbo.


[InterComp_UATManco$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[InterComp_UATManco$Purch_ Rcpt_ Line] l on h.No_=l.[Document No_]

UNION ALL

select (select Name from [O20-O2RENEWABLE E XX PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[O20-O2RENEWABLE E XX PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[O20-O2RENEWABLE E XX PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[O20-O2RENEWABLE E XX PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[O20-O2RENEWABLE E XX PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[O20-O2RENEWABLE E XX PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[O20-O2RENEWABLE E XX PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[O20-O2RENEWABLE E XX PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [O20-O2RENEWABLE E XX PVT LTD$Detailed GST
Ledger Entry] g inner join [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [O20-O2RENEWABLE E XX PVT LTD$Detailed GST


Ledger Entry] g inner join [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [O20-O2RENEWABLE E XX PVT LTD$Detailed GST


Ledger Entry] g inner join [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [O20-O2RENEWABLE E XX PVT LTD$Detailed GST


Ledger Entry] g inner join [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [O20-O2RENEWABLE E XX PVT LTD$Detailed GST
Ledger Entry] g inner join [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [O20-O2RENEWABLE E XX PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [O20-O2RENEWABLE E XX PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[O20-O2RENEWABLE E XX PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[O20-


O2RENEWABLE E XX PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[O20-O2RENEWABLE E XX PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [O21-O2RENEWABLE E XXI PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[O21-O2RENEWABLE E XXI PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[O21-O2RENEWABLE E XXI PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[O21-O2RENEWABLE E XXI PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[O21-O2RENEWABLE E XXI PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[O21-O2RENEWABLE E XXI PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[O21-O2RENEWABLE E XXI PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[O21-O2RENEWABLE E XXI PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [O21-O2RENEWABLE E XXI PVT LTD$Detailed GST
Ledger Entry] g inner join [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [O21-O2RENEWABLE E XXI PVT LTD$Detailed GST


Ledger Entry] g inner join [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [O21-O2RENEWABLE E XXI PVT LTD$Detailed GST


Ledger Entry] g inner join [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [O21-O2RENEWABLE E XXI PVT LTD$Detailed GST


Ledger Entry] g inner join [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [O21-O2RENEWABLE E XXI PVT LTD$Detailed
GST Ledger Entry] g inner join [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [O21-O2RENEWABLE E XXI PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [O21-O2RENEWABLE E XXI PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[O21-O2RENEWABLE E XXI PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[O21-
O2RENEWABLE E XXI PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[O21-O2RENEWABLE E XXI PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [O22-O2RENEWABLE E XXII PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[O22-O2RENEWABLE E XXII PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[O22-O2RENEWABLE E XXII PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[O22-O2RENEWABLE E XXII PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[O22-O2RENEWABLE E XXII PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[O22-O2RENEWABLE E XXII PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]
,(select distinct [HSN_SAC Code] from dbo.[O22-O2RENEWABLE E XXII PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[O22-O2RENEWABLE E XXII PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [O22-O2RENEWABLE E XXII PVT LTD$Detailed GST
Ledger Entry] g inner join [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [O22-O2RENEWABLE E XXII PVT LTD$Detailed GST


Ledger Entry] g inner join [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [O22-O2RENEWABLE E XXII PVT LTD$Detailed GST


Ledger Entry] g inner join [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [O22-O2RENEWABLE E XXII PVT LTD$Detailed GST


Ledger Entry] g inner join [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [O22-O2RENEWABLE E XXII PVT LTD$Detailed
GST Ledger Entry] g inner join [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [O22-O2RENEWABLE E XXII PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [O22-O2RENEWABLE E XXII PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]

from dbo.[O22-O2RENEWABLE E XXII PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.
[O22-O2RENEWABLE E XXII PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[O22-O2RENEWABLE E XXII PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [O23-O2RENEWABLE E XXIII PVT L$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[O23-O2RENEWABLE E XXIII PVT L$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[O23-O2RENEWABLE E XXIII PVT
L$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[O23-O2RENEWABLE E XXIII PVT


L$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[O23-O2RENEWABLE E XXIII PVT L$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[O23-O2RENEWABLE E XXIII PVT
L$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[O23-O2RENEWABLE E XXIII PVT L$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[O23-O2RENEWABLE E XXIII
PVT L$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [O23-O2RENEWABLE E XXIII PVT L$Detailed GST
Ledger Entry] g inner join [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [O23-O2RENEWABLE E XXIII PVT L$Detailed GST


Ledger Entry] g inner join [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [O23-O2RENEWABLE E XXIII PVT L$Detailed GST


Ledger Entry] g inner join [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [O23-O2RENEWABLE E XXIII PVT L$Detailed GST


Ledger Entry] g inner join [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_ Line] pl on
g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [O23-O2RENEWABLE E XXIII PVT L$Detailed
GST Ledger Entry] g inner join [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_ Line] pl
on g.[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [O23-O2RENEWABLE E XXIII PVT L$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [O23-O2RENEWABLE E XXIII PVT
L$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line
No_]=l.[Line No_]) [PI No]

from dbo.[O23-O2RENEWABLE E XXIII PVT L$Purch_ Rcpt_ Header] h inner join dbo.[O23-
O2RENEWABLE E XXIII PVT L$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[O23-O2RENEWABLE E XXIII PVT L$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

UNION ALL

select (select Name from [OR6-O2RENEWABLE E VI PVT LTD$Company Information])


Company,h.[No_] as [GRN No],h.[Buy-from Vendor No_] [Vendor No],h.[Buy-from Vendor
Name] [Vendor Name], h.[Posting Date], gh.[Gate Entry No_],gh.[Gate Entry Date],
h.[Location Code],gh.Remarks, h.[Document Date], h.[Dimension Set ID],h.[Shortcut
Dimension 1 Code],
h.[Shortcut Dimension 2 Code],gh.[Purchase Category], gh.[Vendor Invoice No_],gh.
[Vendor Invoice Date],
---=====
l.[Line No_],l.[No_] [Item No], l.Description [Item Desc], l.[Description 2] [Item
Desc 2], l.[Unit of Measure Code], l.[Order No_] [Purchase Order No_],
l.[Order Line No_],cast(l.Quantity as Numeric(35,2)) Quantity,cast(l.[Direct Unit
Cost] as Numeric(35,2)) [Direct Unit Cost],cast(l.[Unit Cost] as Numeric(35,2))
[Unit Cost],cast(l.[Quantity Invoiced] as Numeric(35,2)) [Quantity Invoiced],l.
[Qty_ Rcd_ Not Invoiced],--[Pending Order Quantity],
[GRN Qty(Posted)],cast([Accepted Quantity] as Numeric(35,2)) [Accepted Quantity],
cast([Rejected Quantity] as Numeric(35,2)) [Rejected Quantity], l.[Return Reason
Code],
l.[Indent No_],[Indent Line No_],l.[Job No_],
[Line Remarks],
Case when gh.Status =0 then 'Open' else 'Closed' end Status,
gh.[CN_RR_LR No_] as [CN_RR_LR No],gh.[CN_RR_LR Date],
gh.[Way Bill No_] as [Way Bill No] ,
(select distinct [HSN_SAC Code] from dbo.[OR6-O2RENEWABLE E VI PVT LTD$Item] m
where m.[No_]=l.[No_] ) [HSN / SEC Code],
(select distinct m.[Item Category Code] from dbo.[OR6-O2RENEWABLE E VI PVT
LTD$Item] m where m.[No_]=l.[No_] ) [Item Category Code],

(select distinct m.[Product Group Code] from dbo.[OR6-O2RENEWABLE E VI PVT


LTD$Item] m where m.[No_]=l.[No_] ) [Product Sub Group Code],
COALESCE(case h.[Workflow Sub Document Type] when 1 Then 'FA' When 2 then
'Regular' When 3 Then 'Direct' When 4 Then 'Work Order' when 5 then 'Inward'
when 6 then 'Outward' when 7 then 'Indent' end,'') as [Workflow Sub Document
Type],
cast((select sum(pl.Quantity) from dbo.[OR6-O2RENEWABLE E VI PVT LTD$Purchase
Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line
No_]) as NUMERIC(35,2)) [PO QTY],
cast((select sum([Amount Including Tax]) from dbo.[OR6-O2RENEWABLE E VI PVT
LTD$Purchase Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.
[Order Line No_]) as NUMERIC(35,2)) [PO Value]

,(select distinct [HSN_SAC Code] from dbo.[OR6-O2RENEWABLE E VI PVT LTD$Purchase


Line] pl where pl.[Document No_]=l.[Order No_] and pl.[Line No_]=l.[Order Line No_]
) [PO HSN/SEC Code],
(select distinct top 1 [GST Registration No_] from dbo.[OR6-O2RENEWABLE E VI PVT
LTD$Vendor] v where v.No_=h.[Buy-from Vendor No_]) [Vendor GST REg No],
cast((select sum([GST Amount]) from [OR6-O2RENEWABLE E VI PVT LTD$Detailed GST
Ledger Entry] g inner join [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='SGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [SGST Amount],

cast((select sum([GST Amount]) from [OR6-O2RENEWABLE E VI PVT LTD$Detailed GST


Ledger Entry] g inner join [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CGST Amount],

cast((select sum([GST Amount]) from [OR6-O2RENEWABLE E VI PVT LTD$Detailed GST


Ledger Entry] g inner join [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='IGST' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [IGST Amount],

cast((select sum([GST Amount]) from [OR6-O2RENEWABLE E VI PVT LTD$Detailed GST


Ledger Entry] g inner join [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] and g.[GST Component Code]='CESS' where
pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line No_]) as
NUMERIC(35,2)) [CESS Amount]
,
(select distinct g.[HSN_SAC Code] from [OR6-O2RENEWABLE E VI PVT LTD$Detailed GST
Ledger Entry] g inner join [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_ Line] pl on g.
[Document No_]=pl.[Document No_]
and g.[Document Line No_]=pl.[Line No_] where pl.[Receipt No_]=l.[Document No_]
and pl.[Receipt Line No_]=l.[Line No_]) [HSN Sec Code],
cast((select sum([TDS Amount]) from [OR6-O2RENEWABLE E VI PVT LTD$Purch_ Inv_
Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt Line No_]=l.[Line
No_]) as NUMERIC(35,2)) [TDS Amount]
,
(select distinct Top 1 pl.[Document No_] from [OR6-O2RENEWABLE E VI PVT
LTD$Purch_ Inv_ Line] pl where pl.[Receipt No_]=l.[Document No_] and pl.[Receipt
Line No_]=l.[Line No_]) [PI No]
from dbo.[OR6-O2RENEWABLE E VI PVT LTD$Purch_ Rcpt_ Header] h inner join dbo.[OR6-
O2RENEWABLE E VI PVT LTD$Goods Receipt Header] gh on h.No_=gh.No_
inner join dbo.[OR6-O2RENEWABLE E VI PVT LTD$Purch_ Rcpt_ Line] l on h.No_=l.
[Document No_]

You might also like