sql - Row Number for a view where the number is not affected by the where clause -


SQL Server 2008

I have a view with several lines, where this is possible the exact line Many times I have already tried ROW_NUMBER above row_id (as per order 1) but ran into a problem:

When using a JOIN or WHERE block, row_ids Dynamically new results are adjusted in the set.

Any thoughts?

EDIT: I have added one that is given for a line without any row. For example, it should have been done before posting.

Without WHERE clause:

SELECT ROW_NUMBER () Select (call 1 according to call 1) as line_ID, result. Select 'Adam' call1, 'West' col2
Union all - SELECT 'Adam' col1, 'Cole' col2
UNION ALL
SELECT 'Adam' col1, 'west' col2
Union All - SELECT 'Danny' col1, 'west' col2

) Result

Result: row_id col1 col2 1 Adam Cole 2 Adam West 3 Adam West 4 Danny West

Now when I use the WHERE section as a line segment

< P> SELECT ROW_NUMBER () uses (ORDER BY COL1), results *
FROM
(

SELECT 'Adam' col1, 'west' col2
UNION ALL
SELECT 'Adam' col1, 'col' col2
Union All - SELECT 'Adam' col1, 'West' colo 2 - Union All - Select Danny 'Call 1, West' Cole 2,

Results WHERE col2 = 'West'

Result:

  row_id col1 col2 1 Adam West 2 Adam West 3 Danny West   

Desired Results:

  row_id col1 col2 2 Adam West 3 Adam West 4 Danny West    

You can generate line numbers in a subquery in the external query join or where are not affected by the section:
 select from  to (select row_number ()) as your Tables , As your TABLE), YourTableWithRowNumber include YourTableWithRowNumber.id in another table with thumb.number.id = otherTable.Your TablesAppetablesWithRobowColl 1 '% includeeem%'    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

jsp - Google line chart x-axis shrinks on transition -

java - Reaching JTextField in a DocumentListener -