J
JonR
Hi
I am getting an error "The SELECT statement contains a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"
I'm really new to using SQL, and obviously forced to use it with a union query. I don't know what exactly I'm looking for or where to find it.
What this query is supposed to do is find all the service requests and associate them with the most recent date. This will be either d_date_submitted or d_app_x_impacted_date. The d_app_x_impacted_date will invariably be later than d_date_submitted, but does not exist for all records. My ultimate output needs to be a list of all service requests associated with the most recent of the two dates, with no duplication in the service requests.
Thanks in advance
SELECT DatePart("yyyy",[d_date_submitted]) AS [Year], DatePart("m",[d_date_submitted]), AS [Month], [dbo_srm_service_requests].[c_service_req]
FROM (dbo_srm_service_requests INNER JOIN dbo_srm_sr_appl_xref ON dbo_srm_service_requests.c_service_req = dbo_srm_sr_appl_xref.c_service_req) INNER JOIN dbo_chip_projects_by_app ON dbo_srm_service_requests.c_service_req = dbo_chip_projects_by_app.c_service_req
WHERE (((dbo_srm_service_requests.c_is_app_id)="ESM" Or (dbo_srm_service_requests.c_is_app_id)="ESMOPS" Or (dbo_srm_service_requests.c_is_app_id)="ESMBSS" Or (dbo_srm_service_requests.c_is_app_id)="ESMPM" Or (dbo_srm_service_requests.c_is_app_id)="ESMSMARTS" Or (dbo_srm_service_requests.c_is_app_id)="ESMTME" Or (dbo_srm_service_requests.c_is_app_id)=" ESMWO" Or (dbo_srm_service_requests.c_is_app_id)="INFOVISTA") AND ((dbo_srm_service_requests.c_project_type)="d")) OR (((dbo_srm_service_requests.c_project_type)="d") AND ((dbo_srm_sr_appl_xref.c_is_app_id)="ESM" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMOPS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMBSS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMPM" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMSMARTS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMTME" Or (dbo_srm_sr_appl_xref.c_is_app_id)=" ESMWO" Or (dbo_srm_sr_appl_xref.c_is_app_id)="INFOVISTA"))
UNION SELECT DatePart("yyyy",[d_app_x_impacted_date]) AS [Year], DatePart("m",[d_app_x_impacted_date]), AS [Month],[ dbo_srm_service_requests].[c_service_req]
FROM ([dbo_srm_service_requests] INNER JOIN [dbo_srm_sr_appl_xref] ON [dbo_srm_service_requests].[c_service_req] =[ dbo_srm_sr_appl_xref].[c_service_req]) INNER JOIN [dbo_chip_projects_by_app] ON [dbo_srm_service_requests].[c_service_req] = [dbo_chip_projects_by_app].[c_service_req]
GROUP BY IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("yyyy",[d_date_submitted]),DatePart("yyyy",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("m",[d_date_submitted]),DatePart("m",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), dbo_srm_service_requests.c_service_req
ORDER BY IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("yyyy",[d_date_submitted]),DatePart("yyyy",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("m",[d_date_submitted]),DatePart("m",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), dbo_srm_service_requests.c_service_req;
I am getting an error "The SELECT statement contains a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"
I'm really new to using SQL, and obviously forced to use it with a union query. I don't know what exactly I'm looking for or where to find it.
What this query is supposed to do is find all the service requests and associate them with the most recent date. This will be either d_date_submitted or d_app_x_impacted_date. The d_app_x_impacted_date will invariably be later than d_date_submitted, but does not exist for all records. My ultimate output needs to be a list of all service requests associated with the most recent of the two dates, with no duplication in the service requests.
Thanks in advance
SELECT DatePart("yyyy",[d_date_submitted]) AS [Year], DatePart("m",[d_date_submitted]), AS [Month], [dbo_srm_service_requests].[c_service_req]
FROM (dbo_srm_service_requests INNER JOIN dbo_srm_sr_appl_xref ON dbo_srm_service_requests.c_service_req = dbo_srm_sr_appl_xref.c_service_req) INNER JOIN dbo_chip_projects_by_app ON dbo_srm_service_requests.c_service_req = dbo_chip_projects_by_app.c_service_req
WHERE (((dbo_srm_service_requests.c_is_app_id)="ESM" Or (dbo_srm_service_requests.c_is_app_id)="ESMOPS" Or (dbo_srm_service_requests.c_is_app_id)="ESMBSS" Or (dbo_srm_service_requests.c_is_app_id)="ESMPM" Or (dbo_srm_service_requests.c_is_app_id)="ESMSMARTS" Or (dbo_srm_service_requests.c_is_app_id)="ESMTME" Or (dbo_srm_service_requests.c_is_app_id)=" ESMWO" Or (dbo_srm_service_requests.c_is_app_id)="INFOVISTA") AND ((dbo_srm_service_requests.c_project_type)="d")) OR (((dbo_srm_service_requests.c_project_type)="d") AND ((dbo_srm_sr_appl_xref.c_is_app_id)="ESM" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMOPS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMBSS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMPM" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMSMARTS" Or (dbo_srm_sr_appl_xref.c_is_app_id)="ESMTME" Or (dbo_srm_sr_appl_xref.c_is_app_id)=" ESMWO" Or (dbo_srm_sr_appl_xref.c_is_app_id)="INFOVISTA"))
UNION SELECT DatePart("yyyy",[d_app_x_impacted_date]) AS [Year], DatePart("m",[d_app_x_impacted_date]), AS [Month],[ dbo_srm_service_requests].[c_service_req]
FROM ([dbo_srm_service_requests] INNER JOIN [dbo_srm_sr_appl_xref] ON [dbo_srm_service_requests].[c_service_req] =[ dbo_srm_sr_appl_xref].[c_service_req]) INNER JOIN [dbo_chip_projects_by_app] ON [dbo_srm_service_requests].[c_service_req] = [dbo_chip_projects_by_app].[c_service_req]
GROUP BY IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("yyyy",[d_date_submitted]),DatePart("yyyy",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("m",[d_date_submitted]),DatePart("m",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), dbo_srm_service_requests.c_service_req
ORDER BY IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("yyyy",[d_date_submitted]),DatePart("yyyy",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), IIf(IsNull([dbo_chip_projects_by_app].[d_app_x_impacted_date]),DatePart("m",[d_date_submitted]),DatePart("m",[dbo_chip_projects_by_app].[d_app_x_impacted_date])), dbo_srm_service_requests.c_service_req;