COMPUTE clause #1, aggregate expression #1 is not in the select list.

  • Newbie at the wheel...

    Taking this table..

    create table test

    (

    color_names varchar(20)

    )

    insert test (color_names) values ('red')

    insert test (color_names) values ('yellow')

    insert test (color_names) values ('blue')

    --couldn't figure out a quick way to create a table 1 column 3 rows in a shorter amount of code....sorry

    select [Color Names] = rtrim(test.color_names)

    from test

    compute count(test.color_names);

    The select statement gives the error mentioned in the subject. If I were to change the line from..

    select [Color Names] = rtrim(test.color_names)

    ...to...

    select test.color_names

    The...

    compute count(test.color_names);

    ...line works fine without error. I think it has to do with the square brackets. The company requiring this data from me is insisting I have the column name in the format exactly like my example (including the space). How do I get around this to make my compute count() line work? I also am trying to use compute sum() on a different field an am getting the same error because of the identifier being in square brackets.

  • Try this:

    create table #test

    (

    color_names varchar(20)

    )

    insert #test (color_names) values ('red')

    insert #test (color_names) values ('yellow')

    insert #test (color_names) values ('blue')

    --couldn't figure out a quick way to create a table 1 column 3 rows in a shorter amount of code....sorry

    select RTRIM(#test.color_names ) AS [Color Names]

    from #test

    SELECT @@ROWCOUNT

    DROP TABLE #test

  • I tried using SELECT @@ROWCOUNT and I can't get it to work with an automated data pull on a schedule. I was trying to use COMPUTE as a suggestion from this post...

    http://www.sqlservercentral.com/Forums/Topic1130103-338-1.aspx">

    http://www.sqlservercentral.com/Forums/Topic1130103-338-1.aspx

  • The expression in the COMPUTE clause's aggregate has to EXACTLY match an expression in the SELECT clause. Your SELECT clause contains a function call, whereas your COMPUTE clause does not. Try the following:

    SELECT [Color Names] = rtrim(test.color_names)

    FROM Test

    Compute Count(rtrim(test.Color_names))

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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

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