September 30, 2019 at 8:10 pm
Hi,
Can you all please help me with the code to create new table using two existing table. Currently, I am trying to use the code mentioned below but it gives me an error "Incorrect syntax near the keyword 'as'"
Select T1.[Company Name],
T1.[Company Number], T1.[ABRF] as [ABRF_2018], T2.[ABRF] as [ABRF_2018]
into [dbo].[ABRF] from T1
Join on [dbo].[ABRF_2018].[Company Number] = [dbo].[ABRF_2017].[Company Number]
Thanks
September 30, 2019 at 8:13 pm
I don't see T2 in your FROM clause and your ON clause looks a bit off.
You need something like this:
Select
T1.[Company Name],
T1.[Company Number],
T1.[ABRF] as [T1_ABRF_2018],
T2.[ABRF] as [T2_ABRF_2018]
into [dbo].[ABRF]
from T1
inner join T2 on [T1].[Company Number] = [T2].[Company Number]
September 30, 2019 at 8:18 pm
You have no T2 table
from T1 join on
should be
from T1 join T2 in
September 30, 2019 at 8:28 pm
Thanks for pointing out . Here is my new code I am trying
Select
T1.[Company Name],
T1.[Company Number],
T1.[ABRF] as [ABRF_2018],
T2.[ABRF] as [ABRF_2017]
into [dbo].[ABRF] from [dbo].[ACAR Historical Data_2018] as T1
inner Join [dbo].[ACAR Historical Data_2017] as T2 on T1.[Company Number] = T2.[Company Number]
I am still getting the error "Invalid object name 'dbo.ACAR Historical Data_2018'"
September 30, 2019 at 8:35 pm
Make sure the table exists and that the user executing the query has SELECT access to it.
As a side note...IMO, it's not a good practice to use spaces in your table names.
September 30, 2019 at 8:37 pm
Yes, this table exist and have access as well. Thanks for pointing out about name, will keep in mind.
September 30, 2019 at 8:38 pm
Are you executing the query in SQL Server Management Studio or something else?
September 30, 2019 at 9:07 pm
Hi,
This is strange if the table exists and you have permission still you get the error?
can you check the schema also?
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy