Access Query Issue - Cannot identify Error 3141 - ms-access

this was working previously and now I cannot figure out where the error is. trying to create a design view table qry
all table and field references are named properly
SELECT
Union.[HARD DOLLAR ENTRY AREA]
, Union.Service
, tblAcctCodes.QtyRollUpTo
, tblAcctCodes.AcctCode
, tblAcctCodes.Desc
, Union.UOM
, SUM(Union.QTY) AS SumOfQTY
, Union.UR
, Union.MH
, tblAcctCodes.MH
, tblAcctCodes.[Is Terminal]
, [is terminal] & [qty] AS Expr1
, tblAcctCodes.[WBS Code] AS CBS
, tblAcctCodes.Level
, tblAcctCodes.[Calc]
, [Calc] & [QTY] AS Expr2
FROM
[Union]
RIGHT JOIN
tblAcctCodes
ON
Union.[Account Code] = tblAcctCodes.AcctCode
GROUP BY
Union.[HARD DOLLAR ENTRY AREA]
, Union.Service
, tblAcctCodes.QtyRollUpTo
, tblAcctCodes.AcctCode
, tblAcctCodes.Desc
, Union.UOM
, Union.UR
,
UNION
.MH
, tblAcctCodes.MH
, tblAcctCodes.[Is Terminal]
, [is terminal] & [qty]
, tblAcctCodes.[WBS Code]
, tblAcctCodes.Level
, tblAcctCodes.[Calc]
, [Calc] & [QTY]
HAVING
(
(
(
[is terminal] & [qty]
)
<>"Yes"
OR
(
[is terminal] & [qty]
)
IS NULL
)
)
ORDER BY
tblAcctCodes.QtyRollUpTo
;

Your originally posted code has a space too much:
Union.UR,
UNION .MH,
tblAcctCodes.MH
Also, don't use a reserved word (UNION) for a query name.

Related

Google Apps Script - Import Contacts from CSV with trigger - TypeError: Cannot read property 'getRange' of null

wann Import Contacts from a CSV File with Google Apps Script
the CSV File is stored on Google Drive.
I found this example:
But did not work for me:
function importCSVFromGoogleDrive() {
var file = DriveApp.getFilesByName('file.csv').next();
Logger.log(file.getSize());
Logger.log(file.getName());
Logger.log(file.getDateCreated());
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
got this error:
14:45:50
Hinweis
Ausführung begonnen
14:45:51
Info
1624.0
14:45:51
Info
file.csv
14:45:51
Info
Fri Sep 17 11:51:35 GMT+02:00 2021
14:45:51
Fehler
TypeError: Cannot read property 'getRange' of null
importCSVFromGoogleDrive
# import.gs:9
How to fix this ?
If i set this line:
Logger.log(Utilities.parseCsv(file.getBlob().getDataAsString()));
I can see the content of the CSV file.
15:27:26
Hinweis
Ausführung begonnen
15:27:26
Info
1624.0
15:27:26
Info
file.csv
15:27:26
Info
Fri Sep 17 11:51:35 GMT+02:00 2021
15:27:27
Info
[[Name, Given Name, Additional Name, Family Name, Yomi Name, Given Name Yomi, Additional Name Yomi, Family Name Yomi, Name Prefix, Name Suffix, Initials, Nickname, Short Name, Maiden Name, Birthday, Gender, Location, Billing Information, Directory Server, Mileage, Occupation, Hobby, Sensitivity, Priority, Subject, Notes, Language, Photo, Group Membership, E-mail 1 - Type, E-mail 1 - Value, Phone 1 - Type, Phone 1 - Value, Address 1 - Type, Address 1 - Formatted, Address 1 - Street, Address 1 - City, Address 1 - PO Box, Address 1 - Region, Address 1 - Postal Code, Address 1 - Country, Address 1 - Extended Address, Organization 1 - Type, Organization 1 - Name, Organization 1 - Yomi Name, Organization 1 - Title, Organization 1 - Department, Organization 1 - Symbol, Organization 1 - Location, Organization 1 - Job Description, Website 1 - Type, Website 1 - Value], [Anna Musterfrau, Anna, , Musterfrau, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * Home, anna#musterfrau.de, Mobile, +491234567890, , , , , , , , , , , , , , , , , , , ], [Hans Meise, Hans, , Meise, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * Home, meinse#hans.de, , , , , , , , , , , , , , , , , , , , , ], [Hans Mustermann, Hans, , Mustermann, , , , , , , , , , , , , , , , , , , , , , , , , * myContacts, * , hans#mustermann.de, Main, +4912345 98765, , Nebenstrasse 122, , , , , , , , , , , , , , , , , ], [Musterhausen 12345, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ], [DE", Nebenstrasse 122, Musterhausen, , , 12345, DE, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ]
How do you run this script?
on https://script.google.com/home with "execude"
the script should run automated with a trigger
so that the contacts will add every day from the CSV file
a script to delete all conacts I found an this work.
But need to add the contacts from CSV file...
Contacts-Source is CSV File, automated import with apps script
every day by using a trigger
Plan is: CSV --> direct Google Contacts Import with Apps Script by using a trigger

Alternate for Indexing

We need result from Table based on datetime filter. But it working slow in mysql. I can't implement indexing on date & timestamp columns due to it will slow our insertion/updation. So can you please suggest any alternate for select the data quickly based on date and datetime filter with better performance.
SQL Query :
SELECT *
FROM (
SELECT id
, title
, language
, lang_code
, financial
, fname
, lname
, mname
, mname_br
, suffix
, CASE WHEN DOB='0000-00-00' THEN NULL ELSE DOB END AS DOB
, street
, street2
, postal_code
, zip_ext
, city
, state
, country_code
, phone_home
, phone_biz
, phone_biz_ext
, phone_contact
, phone_cell
, status
, CASE WHEN date='0000-00-00 00:00:00' THEN NULL ELSE
CAST(date as datetime) END AS date
, sex
, referrer
, referrerID
, providerID
, ethnoracial
, pid
, temp_key
, primary_care
, default_facility
, created_by
, patientStatus
, primary_care_id
, Sec_HCFA
, noBalanceBill
, erx_entry
, erx_patient_id
, athenaID
, CASE WHEN licenseDate='0000-00-00 00:00:00' THEN NULL ELSE licenseDate end as licenseDate
, race
, otherRace
, ethnicity
, otherEthnicity
, primary_care_phy_name
, primary_care_phy_id
, CASE WHEN dod_patient='0000-00-00' THEN NULL ELSE dod_patient END AS dod_patient--
, locked--
, co_man_phy--
, co_man_phy_id--
, vip--
, External_MRN_1--
, External_MRN_2--
, External_MRN_3--
, External_MRN_4
, as_id
, CASE WHEN acc_statement_date='0000-00-00' THEN acc_statement_date END AS acc_statement_date
, CASE WHEN timestamp='0000-00-00 00:00:00' THEN NULL ELSE timestamp END AS timestamp
, api_id
, fmh_pt_status
, race_code
, ethnicity_code
, patient_payer
, CASE WHEN date='0000-00-00 00:00:00' THEN NULL ELSE date END AS transfer_created
,CASE WHEN timestamp='0000-00-00 00:00:00' THEN NULL ELSE timestamp END AS transfer_updated
,CASE WHEN date > '2020-11-10 00:00:00' THEN 'new' ELSE 'changed' END AS flagfield
,CASE WHEN date='0000-00-00 00:00:00' THEN NULL ELSE date END AS sortdate
FROM patient_data
WHERE (date > '2020-11-10 00:00:00' or timestamp > '2019-04-01 19:53:57-04')
AND month(date) > 0)t
ORDER BY flagfield desc,
sortdate;
)
id Column has indexing in the table
Get rid of
SELECT *
FROM (
)t
it adds nothing, except to slow things down.
Let's focus on
SELECT id
FROM patient_data
WHERE (date > '2020-11-10 00:00:00'
or timestamp > '2019-04-01 19:53:57-04')
AND month(date) > 0
Does that shortened query run "too slow"? If not, then we can use that as a derived table to see if that will speed it up. If so, then we will need to get into UNION and indexing.

Combining Two SQL Select Queries with Where Clauses

I have two Oracle queries that I need combined through an inner join where the tables are joined using the person_uid field. This is because I need to compare what an employee's pay, job title, and supervisor was from one year to the next. I need to have the 2015 data and the 2014 data in the same row for each employee, so if this can be done by doing a subquery using an inner join on the person_uid field, that is the method that I believe will accomplish this.
Here is the first query that pulls the necessary 2015 data:
SELECT person_uid,
id ,
position_contract_type,
position,
job_suffix,
position_status,
effective_date,
position_employee_class,
timesheet_organization ,
appointment_pct ,
annual_salary ,
per_pay_salary ,
hourly_rate ,
position_title ,
academic_title ,
supervisor_id ,
supervisor_name ,
supervisor_position ,
supervisor_job_suffix ,
supervisor_title ,
assignment_grade ,
position_change_reason ,
position_change_reason_desc
FROM employee_position_cunm posn
WHERE posn.position_contract_type = 'P'
AND posn.position_status <> 'T'
AND posn.effective_date = (SELECT MAX(effective_date)
FROM employee_position_cunm p2
WHERE p2.person_uid = posn.person_uid
AND p2.position = posn.position
AND p2.job_suffix = posn.job_suffix
AND p2.effective_date <= '01-Nov-2015')
order by person_uid
I need it to be joined to this query on the person_uid field so that each unique ID for the employee has the records for both years in a single row:
SELECT person_uid,
id ,
position_contract_type,
position,
job_suffix,
position_status,
effective_date,
position_employee_class,
timesheet_organization ,
appointment_pct ,
annual_salary ,
per_pay_salary ,
hourly_rate ,
position_title ,
academic_title ,
supervisor_id ,
supervisor_name ,
supervisor_position ,
supervisor_job_suffix ,
supervisor_title ,
assignment_grade ,
position_change_reason ,
position_change_reason_desc
FROM employee_position_cunm posn
WHERE posn.position_contract_type = 'P'
AND posn.position_status <> 'T'
AND posn.effective_date = (SELECT MAX(effective_date)
FROM employee_position_cunm p2
WHERE p2.person_uid = posn.person_uid
AND p2.position = posn.position
AND p2.job_suffix = posn.job_suffix
AND p2.effective_date <= '01-Nov-2014')
order by person_uid
An easy way would be to use OR:
WHERE posn.position_contract_type = 'P' AND
posn.position_status <> 'T' AND
(posn.effective_date = (SELECT MAX(effective_date)
FROM employee_position_cunm p2
WHERE p2.person_uid = posn.person_uid
p2.position = posn.position AND
p2.job_suffix = posn.job_suffix AND
p2.effective_date <= '01-Nov-2014'
) OR
posn.effective_date = (SELECT MAX(effective_date)
FROM employee_position_cunm p2
WHERE p2.person_uid = posn.person_uid
p2.position = posn.position AND
p2.job_suffix = posn.job_suffix AND
p2.effective_date <= '01-Nov-2015'
)
)
In Oracle you could do a UNION or a UNION ALL.
SELECT person_uid,
id ,
position_contract_type,
position,
job_suffix,
position_status,
effective_date,
position_employee_class,
timesheet_organization ,
appointment_pct ,
annual_salary ,
per_pay_salary ,
hourly_rate ,
position_title ,
academic_title ,
supervisor_id ,
supervisor_name ,
supervisor_position ,
supervisor_job_suffix ,
supervisor_title ,
assignment_grade ,
position_change_reason ,
position_change_reason_desc
FROM employee_position_cunm posn
WHERE ...
...
...
UNION ALL
SELECT person_uid,
id ,
position_contract_type,
position,
job_suffix,
position_status,
effective_date,
position_employee_class,
timesheet_organization ,
appointment_pct ,
annual_salary ,
per_pay_salary ,
hourly_rate ,
position_title ,
academic_title ,
supervisor_id ,
supervisor_name ,
supervisor_position ,
supervisor_job_suffix ,
supervisor_title ,
assignment_grade ,
position_change_reason ,
position_change_reason_desc
FROM employee_position_cunm posn
WHERE ....
....
....;

Syntax Error in INSERT INTO statement, no other details given

The SQL generated my code looks like this -
INSERT INTO [Item] (
Vendor_num
, item
, [Desc]
, Pack
, item_size
, unit_of_sale
, allowance
, points
, Promo
, WS_Cost
, WS_Unit_cost
, Retailer_Price
, Retail
, Cust_Use
, Show_Price
, GP
, Min
, Max
, Book_Number
, Del1_date
, Del2_date
, Del3_date
, Del4_date
, Del5_date
, Del6_date
, Del7_date
, Del8_date
, Del9_date
, Del10_date
, Del11_date
, Del12_date
, Del13_date
, Del14_date
, Del15_date
, warehouse
, Purchase_Group
, GPM
, Material_Number
, PM
) VALUES (
'11'
, '300681'
, 'item description'
, '60'
, 'BOX'
, 'BOX'
, '3'
, '20'
, 'Y'
, '0'
, null
, '0'
, null
, '03652'
, null
, null
, null
, null
, '832'
, '6/2/2014 12:00:00 AM'
, '6/30/2014 12:00:00 AM'
, '7/28/2014 12:00:00 AM'
, '8/18/2014 12:00:00 AM'
, null
, null
, null
, null
, null
, null
, null
, null
, null
, null
, null
, '1'
, null
, null
, null
, null
)
(forgive all those null values, they're frequently not null in these inserts, so the statement needs to be flexible enough when they're not)
I'm getting a generic error --
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
The statement works fine when copied directly into a new query in Access, but when firing through .NET and OLE DB, it fails miserably.
Any ideas?
Min and Max are reserved words in Access, and should be quoted if you use them as field names or you may encounter errors;
If a reserved word is already in use, you can avoid error messages by surrounding each occurrence of the word with brackets ([ ]). However, the best solution is to change the name to a nonreserved word.
In other words, used as field names, they should be quoted as [Min] and [Max].

SQL error for operand

I have used the same query to transfer from one database to another for ages, but suddenly I am getting the error
"Operand should contain 1 column(s)"
Here is my SQL:
INSERT INTO lightand_expressionengine.exp_channel_data (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
SELECT (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
FROM lightand_expressionengineold.exp_channel_data
Can anyone see what the issue is? I cant figure it out.
Remove the opening and closing brackets i.e. (...) from the SELECT. I.e. try the following SQL.
INSERT INTO lightand_expressionengine.exp_channel_data (
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
)
SELECT
entry_id
, site_id
, channel_id
, field_id_1
, field_ft_1
, field_id_3
, field_ft_3
, field_id_7
, field_ft_7
, field_id_8
, field_ft_8
, field_id_9
, field_ft_9
, field_id_11
, field_ft_11
, field_id_12
, field_ft_12
, field_id_13
, field_ft_13
, field_id_14
, field_ft_14
, field_id_16
, field_ft_16
, field_id_17
, field_ft_17
FROM lightand_expressionengineold.exp_channel_data