Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a view with Name and Address as colums I would like to add Rownumber (Extras Colum RowNumber) to it on my view Note Not on the table itself Note not IdenetityThanksIf it is that easy, everybody will be doing it
Srinika
Master Smack Fu Yak Hacker
1378 Posts
Posted - 2006-08-25 : 11:29:04
try this
USE Pubsselect [Row #]=count(*), a1.au_lname, a1.au_fname from authors a1, authors a2 where a1.au_lname + a1.au_fname >= a2.au_lname + a2.au_fname group by a1.au_lname, a1.au_fname order by 1
Srinika
snSQL
Master Smack Fu Yak Hacker
1837 Posts
Posted - 2006-08-25 : 11:39:09
I did a quick execution plan comaprison and I think this may be more efficient?use pubsselect (select count(*) from authors where au_lname + au_fname <= a1.au_lname + a1.au_fname) as Row_Number ,a1.au_lname, a1.au_fname from authors a1 order by a1.au_lname, a1.au_fname
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2006-08-25 : 23:53:05
Where do you want to do show data?If you use front end application, do numbering thereMadhivananFailing to plan is Planning to fail
You have to do it on the front end or on the final select statement. What if someone does a select with a WHERE clause on your view? You can only produce row numbers when you know the final question you are asking, and no view can ever know that.If you want a row number for each address no matter how you select them then what you are asking for is just going to mask a missing column in your data model and you should add it (does that make sense??)