Thanks in advance for any help folks can offer. I've been pulling my hair our all day yesterday trying to figure out how to fix this. I received the error below after I added 3 new lines (line 60, 61 and 62). The original code without these 3 new lines has been working for several years so I know there's no issue with the other lines. Not sure what tag this falls under.
Error (-99999) Error in AGRExecSql: Couldn't execute statement (4145): 42000 [Microsoft][SQL Server Native Client 11.0][SQL Server]An expression of non-boolean type specified in a context where a condition is expected, near 'col6'.
Here's my full code (I added row#s just for ease to reference in discussion):
1 DATABASE
2 INSERT INTO $*tab2
3 (
4 client,
5 org_account,
6 account,
7 description_l,
8 description_EX,
9 description_pd,
10 curramount,
11 amount,
12 company,
13 transactiontype,
14 vouchertype,
15 vendorid,
16 payrecipientid,
17 projectid_l,
18 projectid_ex,
19 grantid_l,
20 grantid_ex,
21 repcat_l,
22 repcat_ex,
23 objective_l,
24 objective_ex,
25 /curr_licence/
26 invoicenumber,
27 /resno - Come back to this later/
28 period,
29 invoicedate,
30 duedate,
31 /paydate,/
32 value_date,
33 /purchaseorder/
34 /vouchno/
35 /seqno/
36 /vouchref/
37 /seqref/
38 /pay_plan_id/
39 pay_method,
40 ext_ref,
41 usdamount,
42 glflag,
43 universal_resid,
44 concur_fee_desc,
45 wire_fee_flag,
46 report_key,
47 pers_flag,
48 disp_flag,
49 col29,
50 ca_description,
51 ca_code,
52 ca_amount
53 )
54 SELECT
55 '$client',
56 col75,/org_account/
57 col75,/account/
58 col7+' '+col6+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy',/description_l/
59 /Corpay edit/
60 CASE WHEN col99 = 'Mastercard Corpay' THEN col7+' '+col6+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy') + ' Corpay'
61 ELSE col7+' '+col6+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy') + ' VISA'
62 END,
63 CASE WHEN col75 in (65410,60340,65100) THEN col7+' '+col6+' '+col31+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy')+' '+col41+' '+col49+' '+col128+' to '+col129+' for '+col39 /description_ex - Account List B/
64 WHEN col75 = 65300 THEN col7+' '+col6+' '+col31+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy')+' '+col41+' '+col49+' '+col51+' for '+col39 /description_ex - Account List C/
65 ELSE col7+' '+col6+' '+col31+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy')+' '+col41+' '+col49+' for '+col39
66 END, /description_ex - Account List A/
67 col7+' '+col6+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy'), /personal and disputed description/
68 col77,/curramount/
69 col77,/amount/
70 CASE WHEN col8 = 'CG' THEN 'US' ELSE col8 END, /company/
71 'GL', /transactiontype/
72 'IN',
73 '', /vendorid/
74 '',/payrecipientid - logic needs to be applied here/
75 'CHAPHOLD',/projectid_l/
76 col93,/projectid_ex/
77 'UNALLOCATED',/grantid_l/
78 col94,/grantid_ex/
79 'NONE',/repcat_l/
80 col95,/repcat_ex/
81 'NONE',/objective_l/
82 col96,/objective_ex/
83 /curr_licence/
84 col25+FORMAT(CAST(col16 AS date), 'MMddyyyy')+CAST(( DENSE_RANK ( ) OVER ( Order By col10 ) ) AS varchar(10)),/invoicenumber/
85 /resno - Come back to this later/
86 /*copied Sahar update from SandboxVendorM6 to Production on 8/27/2025 per approval of Chris Miller after test of SandboxBusinessM6
87 CASE WHEN col61 IN ('Company Billed/Company Paid')
88 THEN cast(datepart(YEAR,col69) as varchar(10))+RIGHT('00'+cast(datepart(MONTH,col69) as varchar(10)) ,2)
89 ELSE cast(datepart(YEAR,col29) as varchar(10))+RIGHT('00'+cast(datepart(MONTH,col29) as varchar(10)) ,2) END, */
90 cast(datepart(YEAR,col29) as varchar(10))+RIGHT('00'+cast(datepart(MONTH,col29) as varchar(10)) ,2), /period/
91 /*Sahar
92 CASE
93 WHEN col61 IN ('Company Billed/Company Paid') AND col99 IN ('Bank of America VISA Corporate Card CBCP - US', 'Key Travel BoA Visa',Mastercard Corpay')
94 THEN cast(datepart(YEAR,col69) as varchar(10))+ '-' + RIGHT('00'+cast(datepart(MONTH,col69) as varchar(10)) ,2) + '-28'
95 WHEN col61 IN ('Company Billed/Company Paid')
96 THEN col69
97 ELSE col29 END, */
98 col29,/invoicedate/
99 col29,/duedate/
100 /paydate - BLANK/
101 CASE WHEN col61 IN ('Company Billed/Company Paid')
102 THEN col69
103 ELSE col29 END,/value_date/
104 /purchaseorder - BLANK/
105 /vouchno - Agresso To Populate/
106 /seqno - Agresso To Populate/
107 /vouchrer - BLANK/
108 /seqref - BLANK/
109 /pay_plan_id - BLANK/
110 '',/pay_method - Come Back to This Later/
111 col10,/ext_ref/
112 col77,
113 CASE WHEN col61 in ('Company Billed/Company Paid') THEN 'Y' ELSE 'N' END,
114 col5,
115 col7+' '+col6+' '+col25+''+FORMAT(CAST(col16 AS date), 'MMddyyyy'),
116 col28,
117 col11,/*report key */
118 CASE WHEN col6