Keyword LineNo

  • Hello,

     

    Is LineNo a keyword? It comes up blue when typed in QA but there's nothing in BOL about it.

     

    Thanks

     

  • Simple answer = Yes. Search on LineNo within BOL and one of the hits is the Reserved Keywords list and LINENO is in there as a SQL Server reserved keyword. I have no real idea what it is for, though. I would guess it is somehow related to the error line number.

  • I figured it was a reserved keyword. I guessed it was something similar to the rownum function (think thats what its called) in Oracle which you can use in a where clause to restrict which rows are displayed from a resultset.

     

    Then I thought about it and remembered from somewhere that Yukon has this functionality so I tried

    use adventureworks

    go

    select * from person.contact

    where lineno > 1

    on my Beta2 installation but it threw an error on LineNo.

     

    So, why is LineNo reserved? And now here's another question, what's the keyword in Yukon that is akin to rownum in Oracle (if there is one)?

     

  • I still don't know why LineNo is reserved, but I think you are after SET ROWCOUNT X which is like an external TOP that also works on UPDATEs and DELETEs.

  • Hi Aaron,

    Thanks for that but no, thats not it. Rowcount and Top only return from the "top" of a resultset.

    Maybe I imagined it (very possible) but I'm sure I remember reading somewhere that Yukon was getting something equivalent to ROWNUM in Oracle. Even PostGreSQL has this in the form of its LIMIT function.

    The function I'm thinking of would let you (e.g.) only return the 10th and 11th rows in a resultset by doing something like this:

    SELECT * FROM MyTable

    WHERE rownum IN (10,11)

     

    Its a nice-to-have!

  • I've found what I was looking for. The function is called ROW_NUMBER(). Here's an example of its usage:

    select  row_number() over (order by name) as row_num

    ,  name

    from sys.all_objects order by name

     

    Still don't know what LineNo is supposed to be for though!!!

     

Viewing 6 posts - 1 through 6 (of 6 total)

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