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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem On Row_Number() -Union Clause

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2009-06-12 : 05:48:53
How To Get Row Number In UnionClause

SELECT TOP 10
FROM(SELECT ROW_NUMBER() OVER (Order By DISMAST.Id DESC) AS SlNo,
DISMAST.Dispatch_Id AS Dispatch_Id,
FROM TABLE1 DISMAST

UNION
Tmp.SlNo,
TmpDispatch_Id
FROm @tbl_test Tmp
)
ORDER BY SlNo


I have Getting SlNo as 1,1,2,2.....
I want to Get RowNumber like 1,2,3......

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-12 : 05:55:54
Without any sample data and expected output, this is just winging it.
SELECT TOP 10	ROW_NUMBER() OVER (ORDER BY Id DESC) AS SlNo,
Dispatch_Id
FROM (
SELECT Id,
Dispatch_Id
FROM Table1

UNION ALL

SELECT Id,
Dispatch_Id
FROM @Tbl_Test
) AS d
ORDER BY SlNo



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

aoriju
Posting Yak Master

156 Posts

Posted - 2009-06-12 : 06:57:48
Thanks Peso
Its Working
Go to Top of Page
   

- Advertisement -