Trying to create new table using two existing tables in Management studio

  • 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

  • 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]
  • You have no T2 table

    from T1 join on

    should be

    from T1 join T2 in

  • 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'"

  • 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.

  • Yes, this table exist and have access as well. Thanks for pointing out about name, will keep in mind.

  • Are you executing the query in SQL Server Management Studio or something else?

  • 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 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply