SQL query Problem

  • Hi,

    im trying to catch in a local variable the number of rows of that select:

    set @Filas = (select count(*) SalOtrasNoPetroleras from

    VariablePromedio B,dbo.Homologacion H

    where B.IDVariableProm = H.IDPagoVariable

    and SUBSTRING (convert(varchar(20), H.IDEmpresa) , 4 , 1 ) = '4'

    and H.IDOcupacion = 1

    and B.SalOtrasNoPetroleras <> 0

    ORDER BY SalOtrasNoPetroleras)

    butt it shows me and error:

    Msg 1033, Level 15, State 1, Line 7

    The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

    Thank you any help

  • try this

    select @Filas = count(*)

    from

    VariablePromedio B,dbo.Homologacion H

    where B.IDVariableProm = H.IDPagoVariable

    and SUBSTRING (convert(varchar(20), H.IDEmpresa) , 4 , 1 ) = '4'

    and H.IDOcupacion = 1

    and B.SalOtrasNoPetroleras <> 0

    ORDER BY SalOtrasNoPetroleras

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • oh and why do you have an order by if you doing a count?

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • thats right i dont need that order by, i remove it and works great.

    Thank you Christopher.

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

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