-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_account_tracking.sql
83 lines (76 loc) · 2.06 KB
/
create_account_tracking.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- =============================================
-- Author: Tom Barkley
-- Create date: 8/31/2022
-- Description: This is a sample script that will create a new account tracking record and fill in a few fields
-- =============================================
-- this is written as if it were from the main ARCU db so you will want to change the USE statement to the actual main ARCU db
USE [cu]
GO
-- Declare the most recent process date for the query
DECLARE @ProcessDate INT = (SELECT MAX(ProcessDate) FROM dbo.ACCOUNT);
-- Declare the table that will hold the FM journal
DECLARE @InputFMTable cu.pro.FMTableType;
-- target the accounts based on arbitrary criteria
SELECT
nm.PARENTACCOUNT as AccountNumber
INTO #tmp_example_accounts
FROM dbo.NAME as nm
WHERE
nm.ProcessDate = @ProcessDate
AND nm.TYPE = 0
AND nm.FIRST = 'Tom'
-- insert the changes into the FMTable
INSERT INTO @InputFMTable
-- insert the tracking type
SELECT
pro.FMCreateAccountTrackingRecord(
ac.AccountNumber
),
pro.FMCreateChangeLine(
'Code',
'TYPE',
125
)
FROM #tmp_example_accounts as ac;
-- insert a random date
UNION ALL
SELECT
pro.FMCreateAccountTrackingRecord(
ac.AccountNumber
),
pro.FMCreateChangeLine(
'Date',
'USERDATE1',
GETDATE()
)
FROM #tmp_example_accounts as ac;
-- insert a character
UNION ALL
SELECT
pro.FMCreateAccountTrackingRecord(
ac.AccountNumber
),
pro.FMCreateChangeLine(
'Character',
'USERCHAR1',
'Tom was here'
)
FROM #tmp_example_accounts as ac;
-- insert a money value
UNION ALL
SELECT
pro.FMCreateAccountTrackingRecord(
ac.AccountNumber
),
pro.FMCreateChangeLine(
'Money',
'USERAMOUNT1',
100.00
)
FROM #tmp_example_accounts as ac;
-- call the stored procedure to output the FM journal
EXEC pro.FMOutput @FMTable = @InputFMTable;
-- retrieve the records from the temp table for export to a CSV
SELECT * FROM #tmp_example_accounts;
-- clean up the temp table
DROP TABLE #tmp_example_accounts;