Hi,
I'm new to MS SQL.
I have to write a procedure, to get the changes made in a table, between two version.
I have a table. Account_history. whenever there is change in any of the fields, the data is captured with a new version (account_version). My procedure will take the input parameters as, the account_id, the start_Date and the end_date. the output needs to be
saved in a temp table, with the changes made in the table for this account number ,between the start and the end dates. another thing is, the user might give 'ALL', for 'ALL' the account numbers or may give 2,3 account ids separated by a comma.
the sample data is given below.
CREATE TABLE [dbo].[account_history](
[account_id] [int] NULL,
[account_type] [int] NULL,
[account_name] [varchar](32) NULL,
[account_number] [varchar](32) NULL,
[holder_id] [int] NULL,
[description] [varchar](255) NULL,
[user_id] [int] NULL,
[last_update] [datetime] NULL,
[account_version] [int] NULL,
[account_status] [int] NULL,
[account_class] [int] NULL,
[on_bal_sheet_flag] [tinyint] NULL,
[allow_multi_units] [tinyint] NULL,
[linked_account_id] [int] NULL,
[portfolio_id] [int] NOT NULL,
[clearing_flag] [int] NOT NULL,
[account_legal_name] [varchar](255) NOT NULL,
[account_country] [int] NOT NULL,
[treasury_manager] [int] NOT NULL,
[business_unit_owner] [int] NOT NULL,
[date_opened] [datetime] NOT NULL,
[date_closed] [datetime] NOT NULL,
[general_ledger_account] [varchar](255) NOT NULL,
[base_currency] [int] NOT NULL,
[sweep_enabled_flag] [int] NOT NULL,
[nostro_memo_flag] [int] NOT NULL,
[plink_account_id] [int] NOT NULL,
[account_iban] [varchar](255) NOT NULL
) ON [PRIMARY]
;
account_id account_type account_name account_number holder_id description user_id last_update account_version account_status account_class on_bal_sheet_flag allow_multi_units linked_account_id portfolio_id clearing_flag account_legal_name account_country treasury_manager
business_unit_owner date_opened date_closed general_ledger_account base_currency sweep_enabled_flag nostro_memo_flag plink_account_id account_iban
20001 0 STA LME - USD - 000157210 157210 20203 20005 00:43.3 1 1 20008 0 0 20001 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20002 0 BRC LME - USD - 280231234 280231234 20192 20005 00:43.3 1 1 20008 0 0 20002 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20003 0 CRS LME - USD - 8900360968 8900360968 20189 20005 00:43.3 1 1 20008 0 0 20003 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20004 0 JBL LME - USD - 400124971 400124971 20213 20005 00:43.4 1 1 20008 0 0 20004 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20005 0 JPM LME - USD - 844007443 844007443 20213 20005 00:43.4 1 1 20008 0 0 20005 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20006 0 KMT LME - USD - 4277026903 GB58CHAS60924277026903 20211 20005 00:43.4 1 1 20008 0 0 20006 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20007 0 MAC LME - USD - 8900055375 8900055375 20189 20005 00:43.4 1 1 20008 0 0 20007 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20008 0 BOA LME - USD - 6550660515 6550660515 20187 20005 00:43.4 1 1 20008 0 0 20008 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20009 0 MBC LME - USD - 4215124191 GB38CHAS60924215124191 20211 20005 00:43.4 1 1 20008 0 0 20009 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20010 0 BRC FX - USD - 280231234 280231234 20192 20005 00:43.5 1 1 20008 0 0 20010 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
20011 0 BRC FX - SGD - 0109301870 109301870 20235 20005 00:43.5 1 1 20008 0 0 20011 0 0 0 0 0 00:00.0 00:00.0 57 0 0 0
20012 0 BRC FX - JPY - 4835 4835 20236 20005 00:43.5 1 1 20008 0 0 20012 0 0 0 0 0 00:00.0 00:00.0 54 0 0 0
20013 0 BRC FX - CHF - 044000.05B CH980023 0230044000.05B 20237 20005 00:43.5 1 1 20008 0 0 20013 0 0 0 0 0 00:00.0 00:00.0 52 0 0 0
20014 0 BRC FX - CZK - 8115120287 CZ8201000000278115120287 20227 20005 00:43.5 1 1 20008 0 0 20014 0 0 0 0 0 00:00.0 00:00.0 58 0 0 0
20015 0 BRC FX - GBP - 5258088306 GB26BARC20005258088306 20191 20005 00:43.5 1 1 20008 0 0 20015 0 0 0 0 0 00:00.0 00:00.0 53 0 0 0
20016 0 BRC FX - EUR - 5212990655 GB65BARC20005212990655 20191 20005 00:43.6 1 1 20008 0 0 20016 0 0 0 0 0 00:00.0 00:00.0 51 0 0 0
20017 0 BNP FX - USD - 9409300136 2.00194E+13 20176 20005 00:43.6 1 1 20008 0 0 20017 0 0 0 0 0 00:00.0 00:00.0 0 0 0 0
Please help me
Regards
Prabhu