none
No column was specified for column 1 of 'M'. RRS feed

  • Question

  • Hi

    Select Count(*) From (Select 'Y' Union Select 'N')

    Msg 8155, Level 16, State 2, Line 1

    No column was specified for column 1 of 'M'.

    Why?

    Tuesday, June 11, 2013 5:55 AM

Answers

  • Need to explicily provide a column name for union/union all sub query. Also, Need to aliase the the derived table too.

    Try the below:

    Select Count(*) From (Select 'Y' Col1 Union Select 'N') a


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


    Tuesday, June 11, 2013 5:58 AM
    Answerer
  • All the columns in derived tables are to be named and the table it self.

    Try this,

    Select Count(*) From (Select 'Y' As 'column1' Union Select 'N') as 'table1'

     

    Thanks
    Sarat

    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Tuesday, June 11, 2013 6:00 AM
    Answerer

All replies

  • Need to explicily provide a column name for union/union all sub query. Also, Need to aliase the the derived table too.

    Try the below:

    Select Count(*) From (Select 'Y' Col1 Union Select 'N') a


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


    Tuesday, June 11, 2013 5:58 AM
    Answerer
  • All the columns in derived tables are to be named and the table it self.

    Try this,

    Select Count(*) From (Select 'Y' As 'column1' Union Select 'N') as 'table1'

     

    Thanks
    Sarat

    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Tuesday, June 11, 2013 6:00 AM
    Answerer
  • Select Count(*) From (Select 'Y' AS 'col1' Union Select 'N' AS 'col2')

    GIVE ALIASES FOR COLUMNS

    Saturday, December 14, 2019 5:23 AM