CREATE TABLE [dbo].[Trxntable](
[Currency] [varchar](3) NULL,
[Amount] [decimal](18, 2) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[Trxntable] ([Currency], [Amount]) VALUES (N'840', CAST(100.00 AS Decimal(18, 2)))
INSERT [dbo].[Trxntable] ([Currency], [Amount]) VALUES (N'702', CAST(-100.00 AS Decimal(18, 2)))
INSERT [dbo].[Trxntable] ([Currency], [Amount]) VALUES (N'840', CAST(-200.00 AS Decimal(18, 2)))
INSERT [dbo].[Trxntable] ([Currency], [Amount]) VALUES (N'702', CAST(150.00 AS Decimal(18, 2)))
select SUM(Amount)[TotalAmount],Currency from Trxntable group by Currency
I would like to get as one rows based on amount and currency,if amount less than zero want to take as debit currecy and debit amount else credit,please help suggest any way

