Insert into brand new not created table

  • I am not sure why my insert or into is not working in my SQL Server R2 2008. I have a code I am using on an existing table and trying to put the data in a brand new table but it keeps giving me an error

    select mCid, caucasian, aa, api, aian, mr, his, max(val)

    into memberrand

    from MEMBERV2_RAND

    cross apply (

    select AA union all

    select API union all

    select AIAN union all

    select MR union all

    select HIS union all

    select CAUCASIAN

    ) v(val)

    group by mCid, AA, API, AIAN, MR, HIS, caucasian

    ;

    The error is: Msg 1038, Level 15, State 5, Line 1

    An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

    Do I have to actually create this table with no values first and then run the query? I was hoping this was sort of a make a table query

  • You need to alias your max(val) column. 😉

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Oh my gosh. Such a simple thing I forgot. Thanks so much

Viewing 3 posts - 1 through 2 (of 2 total)

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