简体   繁体   中英

row_number() function

How to use the row_number function in a view?

I use it like this:

SELECT 
    ROW_NUMBER() OVER (ORDER BY name ASC), 
    name, family, mobile, tell
FROM  
    dbo.customer

but SQL Server throws this error:

SQL text cannot be represented in the grid pane and diagram pane.

The error is: "SQL text cannot be represented in the grid pane and diagram pane" ?

Well, the query designer doesn't support row_number . Try your query in a normal sql query editor. The query designer is almost useless because it still has bugs and lacks many things(like this).

You should also give it a name:

SELECT ColName = row_number()over(order by name asc), name, family, mobile, tell
FROM  dbo.customer

You can use row_number() in a view, but you need to give it a name to use in a view:

SELECT row_number() over (order by name asc) as seqnum,
       name, family, mobile, tell
FROM dbo.customer;

The problem is your column [name] , and that it's of the data type text . That particular data type has been deprecated since 2000/2005 iirc.

If you need to be doing sort operations on your [name] column, it'll need to be a different datatype. You should be using a (n)varchar(MAX) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM