Click here to Skip to main content
15,885,900 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(
SELECT top 100 
	a.[CUST_NUM],
	a.[BILLED_AMOUNT_202008],
    a.[BILLED_AMOUNT_202007],
	b.[PROD_FAMILY_GRP],
    b.[PROD_FAMILY],
    b.[PROD_LINE]


FROM [MOBILE_PLANNING].[dbo].[C_prod_grp_202108] as b
	left join [MOBILE_PLANNING].[dbo].[C_mob_br_specialist_details_202012] as a on a.[GL_ACCOUNT_CODE] = b.[SEF_CD]
) as c


What I have tried:

Not sure how i could give the join table an alias, i get an error when i try to add "as c" after the bracket


Msg 156, Level 15, State 1, Line 18
Incorrect syntax near the keyword 'as'.
Posted
Updated 26-Aug-21 18:19pm
Comments
Richard Deeming 27-Aug-21 4:25am    
There is no "line 18" in your code sample. This is presumably part of a larger query, which you haven't shown.

1 solution

You don't need AS keyword after the table. Also you have use AS in the end of the query to 'name' the name it, that's not correct in SQL syntax if this is the whole statement.

Try something like
SQL
SELECT top 100 
	a.[CUST_NUM],
	a.[BILLED_AMOUNT_202008],
    a.[BILLED_AMOUNT_202007],
	b.[PROD_FAMILY_GRP],
    b.[PROD_FAMILY],
    b.[PROD_LINE]
FROM [MOBILE_PLANNING].[dbo].[C_prod_grp_202108] b
LEFT JOIN [MOBILE_PLANNING].[dbo].[C_mob_br_specialist_details_202012] a 
          ON a.[GL_ACCOUNT_CODE] = b.[SEF_CD]
 
Share this answer
 
Comments
Richard Deeming 27-Aug-21 4:24am    
"You don't need AS keyword after the table."

But it's not forbidden. FROM table AS alias will work the same as FROM table alias. :)
Wendelius 27-Aug-21 6:10am    
Exactly, it's nor forbidden in newer version. Can't remember the exact version where using AS become possible but before that it was not supported.
Richard Deeming 27-Aug-21 7:26am    
I don't recall a version of SQL Server where it wasn't allowed. Maybe 6.5? I never really used that version.
Wendelius 30-Aug-21 9:57am    
You've missed a lot :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900