Hi,
I'm Prateek.
I'm storing credit, debit, opening balance, closing balance, and date in one table to generate account statements.
Below is my table script with sample data for your reference:
USE [testDB]
GO
/****** Object: Table [dbo].[ledgers] Script Date: 07-11-2022 16:38:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ledgers](
[id] [int] IDENTITY(1,1) NOT NULL,
[cdate] [varchar](50) NULL,
[ctime] [varchar](50) NULL,
[voucher_no] [int] NULL,
[account_id] [varchar](100) NULL,
[opening_balance] [decimal](18, 2) NULL,
[debit] [decimal](18, 2) NULL,
[debit_particulars] [nvarchar](max) NULL,
[credit] [decimal](18, 2) NULL,
[credit_particulars] [nvarchar](max) NULL,
[closing_balance] [decimal](18, 2) NULL,
[remarks] [varchar](200) NULL,
CONSTRAINT [PK_account_ledgers] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[ledgers] ON
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (1, N'11-06-2022
', NULL, 4, N'8310403169', CAST(211450.00 AS Decimal(18, 2)), NULL, NULL, CAST(84000.00 AS Decimal(18, 2)), NULL, CAST(295450.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (2, N'30-07-2022
', NULL, 21, N'8310403169', CAST(295450.00 AS Decimal(18, 2)), NULL, NULL, CAST(182050.00 AS Decimal(18, 2)), NULL, CAST(477500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (3, N'30-07-2022
', NULL, NULL, N'8310403169', CAST(477500.00 AS Decimal(18, 2)), CAST(150000.00 AS Decimal(18, 2)), N'EMPLOYEE SALARY', NULL, NULL, CAST(327500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (4, N'30-07-2022
', NULL, NULL, N'8310403169', CAST(327500.00 AS Decimal(18, 2)), CAST(50000.00 AS Decimal(18, 2)), N'KASINATH.M
', NULL, NULL, CAST(277500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (5, N'05-05-2022
', NULL, NULL, N'8310403169', CAST(277500.00 AS Decimal(18, 2)), CAST(35000.00 AS Decimal(18, 2)), N'KASINATH.M
', NULL, NULL, CAST(242500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (6, N'08-08-2022
', NULL, 36, N'8310403169', CAST(242500.00 AS Decimal(18, 2)), NULL, NULL, CAST(238000.00 AS Decimal(18, 2)), NULL, CAST(480500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (7, N'10-08-2022
', NULL, NULL, N'8310403169', CAST(480500.00 AS Decimal(18, 2)), CAST(100000.00 AS Decimal(18, 2)), N'MAHIBOOB.W
', NULL, NULL, CAST(380500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (8, N'10-08-2022
', NULL, NULL, N'8310403169', CAST(380500.00 AS Decimal(18, 2)), CAST(50000.00 AS Decimal(18, 2)), N'KASINATH.M
', NULL, NULL, CAST(330500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (9, N'19-08-2022
', NULL, NULL, N'8310403169', CAST(330500.00 AS Decimal(18, 2)), CAST(50000.00 AS Decimal(18, 2)), N'MAHIBOOB.W
', NULL, NULL, CAST(280500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (10, N'30-08-2022
', NULL, 54, N'8310403169', CAST(280500.00 AS Decimal(18, 2)), NULL, NULL, CAST(44750.00 AS Decimal(18, 2)), NULL, CAST(325250.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (11, N'03-09-2022
', NULL, 61, N'8310403169', CAST(325250.00 AS Decimal(18, 2)), NULL, NULL, CAST(55250.00 AS Decimal(18, 2)), NULL, CAST(380500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (12, N'06-09-2022
', NULL, 63, N'8310403169', CAST(380500.00 AS Decimal(18, 2)), NULL, NULL, CAST(44000.00 AS Decimal(18, 2)), NULL, CAST(424500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (13, N'07-09-2022
', NULL, 64, N'8310403169', CAST(424500.00 AS Decimal(18, 2)), NULL, NULL, CAST(44000.00 AS Decimal(18, 2)), NULL, CAST(468500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (14, N'08-09-2022
', NULL, 65, N'8310403169', CAST(468500.00 AS Decimal(18, 2)), NULL, NULL, CAST(43000.00 AS Decimal(18, 2)), NULL, CAST(511500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (15, N'19-09-2022
', NULL, NULL, N'8310403169', CAST(511500.00 AS Decimal(18, 2)), CAST(50000.00 AS Decimal(18, 2)), N'MAHIBOOB.W
', NULL, NULL, CAST(461500.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (16, N'28-09-2022
', NULL, 93, N'8310403169', CAST(461500.00 AS Decimal(18, 2)), NULL, NULL, CAST(36750.00 AS Decimal(18, 2)), NULL, CAST(498250.00 AS Decimal(18, 2)), NULL)
GO
INSERT [dbo].[ledgers] ([id], [cdate], [ctime], [voucher_no], [account_id], [opening_balance], [debit], [debit_particulars], [credit], [credit_particulars], [closing_balance], [remarks]) VALUES (17, N'10-10-2022
', NULL, 106, N'8310403169', CAST(498250.00 AS Decimal(18, 2)), NULL, NULL, CAST(24750.00 AS Decimal(18, 2)), NULL, CAST(523000.00 AS Decimal(18, 2)), NULL)
GO
SET IDENTITY_INSERT [dbo].[ledgers] OFF
GO
Now I want to show data in the crystal reports but it is showing nulls when there are nulls in either debit or credit columns like the
I want it to show in a uniform manner without any nulls.
Please help me achieve this. Thanks in advance.