Search code examples
sqlms-accessselectcreate-table

Cannot use the SQL statement to create table but can use it for query


I have the following code:

SELECT financial_info.date_month, financial_info.date_year, division_info.practice_id, division_info.site_name, department_info.ID AS dept_uid, department_info.dept_id, department_info.dept_name, staff_data.ID AS staff_uid, staff_data.staffid, employee_name_id_info.ID AS emp_name_uid, employee_name_id_info.[Employee Name] AS emp_name, revctr_to_divdept.ID AS rev_cent_uid, revctr_to_divdept.revenue_id, financial_info.[Date of Hire], financial_info.[Date of Term], IIf([financial_info].[date_year]>Year([financial_info].[Date of Hire]),IIf(IsNull([financial_info].[Date of Term]) Or IsMissing([financial_info].[Date of Term]) Or IsEmpty([financial_info].[Date of Term]),True,IIf([financial_info].[date_year]>Year([financial_info].[Date of Term]),False,IIf([financial_info].[date_year]=Year([financial_info].[Date of Term]),IIf([financial_info].[date_month]>Month([financial_info].[Date of Term]),False,True)))),IIf([financial_info].[date_year]=Year([financial_info].[Date of Hire]),IIf([financial_info].[date_month]<Month([financial_info].[Date of Hire]),False,IIf(IsNull([financial_info].[Date of Term]) Or IsMissing([financial_info].[Date of Term]) Or IsEmpty([financial_info].[Date of Term]),True,IIf([financial_info].[date_year]>Year([financial_info].[Date of Term]),False,IIf([financial_info].[date_year]=Year([financial_info].[Date of Term]),IIf([financial_info].[date_month]>Month([financial_info].[Date of Term]),False,True))))),False)) AS is_employed INTO 0_dr_id_by_month
FROM (division_info INNER JOIN (department_info INNER JOIN revctr_to_divdept ON department_info.ID = revctr_to_divdept.[Financial Dept]) ON division_info.practice_id = revctr_to_divdept.practiceid) INNER JOIN ((employee_name_id_info INNER JOIN financial_info ON employee_name_id_info.ID = financial_info.[Employee Name]) INNER JOIN staff_data ON employee_name_id_info.ID = staff_data.fin_data_link) ON revctr_to_divdept.ID = staff_data.revenue_center_name
WHERE (((financial_info.IsDoctor)=True));

This code executes flawlessly when I use it for a select query. When I try to create a table based on the above code, it says the calculated expression is not valid. Any ideas why this is the case?

Thanks Jon


Solution

  • If your query is executing flawlessly as you are saying, you can save it as:qryName Then go to Create->Query Design->SQL View and place the following code:

     SELECT * 
     into [0_dr_id_by_month]
     from qryName;