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.
How To Get Row Number In UnionClauseSELECT 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_IdFROm @tbl_test Tmp)ORDER BY SlNoI 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_IdFROM ( SELECT Id, Dispatch_Id FROM Table1 UNION ALL SELECT Id, Dispatch_Id FROM @Tbl_Test ) AS dORDER BY SlNo