MS Query Incorrect syntax near the keyword 'AS'

Jubert

New Member
Joined
Jun 1, 2016
Messages
28
I am trying to amend SQL in MS query and the error "Incorrect Syntax near the keyword AS" is being returned when I submit this code. What is wrong with the AS in this case? I've searched similar threads and tried to apply advice but still haven't managed to get it to work.
Thanks in advance

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">SELECT
ARM_GP_GROUPINGS.GrpCode,
arm_cc_group_names.cc_name,
CST_COSTCENTRE.CC_CODE,
CST_COSTCENTRE.CC_NAME,
CST_COSTCENTRE.CC_LEVELPOINTER,
CST_COSTHEADER.CH_CODE,
CST_COSTHEADER.CH_NAME,
CST_COSTHEADER.CH_USER3,
CST_COSTHEADER.CH_USER4,
CST_DETAIL.CT_NETT,
CST_DETAIL.CT_SORTTYPE,
CST_DETAIL.CT_PERIODNUMBR,
CST_DETAIL.CT_YEAR,
SL_ACCOUNTS.CUCODE,
SL_ACCOUNTS.CUNAME,
CST_COSTHEADER.CH_CODE

FROM
MWLIVE.dbo.CST_DETAIL CST_DETAIL
AS Detail
INNER
JOIN MWLIVE.dbo.CST_COSTCENTRE CST_COSTCENTRE
AS Costcentre
ON Costcentre.CC_CODE = Detail.CT_COSTCENTRE
INNER
JOIN MWLIVE.dbo.CST_COSTHEADER CST_COSTHEADER
AS Costheader
ON Costheader.CH_CODE = Costcentre.CC_COPYHEADER
LEFT OUTER
JOIN Costcentre
ON Costcentre.CC_LEVELPOINTER = MWLIVE.dbo.arm_cc_group_namesarm_cc_group_names.cc_levelpointer
LEFT OUTER
JOIN Costheader
ON Costheader.CH_ACCOUNT = MWLIVE.dbo.SL_ACCOUNTS SL_ACCOUNTS.CUCODE
INNER
JOIN Costheader
ON Costheader.CH_CODE = MWLIVE.dbo.ARM_GP_GROUPINGS ARM_GP_GROUPINGS.ch_code

WHERE ((CST_DETAIL.CT_YEAR='C') AND (CST_DETAIL.CT_PERIODNUMBR=1))</code>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Your table aliasing doesn't look right

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">FROM
MWLIVE.dbo.CST_DETAIL Detail
INNER
JOIN MWLIVE.dbo.CST_COSTCENTRE Costcentre
ON Costcentre.CC_CODE = Detail.CT_COSTCENTRE
INNER
JOIN MWLIVE.dbo.CST_COSTHEADER Costheader
ON Costheader.CH_CODE = Costcentre.CC_COPYHEADER</code>
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top