troubleshooting Question

row_number to select rownumber =1 records

Avatar of chokka
chokkaFlag for United States of America asked on
Microsoft SQL Server 2008Microsoft SQL Server 2005Microsoft SQL Server
3 Comments1 Solution455 ViewsLast Modified:
I have to use ROW_Number for Union All Syntax which combines two tables. Just confused on implementing this syntax. Do i need to transfer end results to a View Table or Table and then use row_number ?? Looking for best optimized results as because, we have around 10,000 records and keep growing.

,ROW_NUMBER() over (PARTITION BY LastName,Firstname,dateofbirth,
                                                             City ORDER BY
                                                             dateofbirth ASC) as RowNumber

and then i need to pick by rownumber = 1

select PatCustId = '0',FirstName,LastName,DateOfBirth,City from voeorderwide
                                        WHERE  datefilled >= DATEADD(DAY, -90, DATEDIFF(DAY, 0, GETDATE()))
                                        Union All
                                 select PatCustId = '0',FirstName,LastName,DateOfBirth,City from voeorderhistorywide
                                        WHERE datefilled >= DATEADD(DAY, -90, DATEDIFF(DAY, 0, GETDATE()))       

Open in new window

Contract ERP Admin/Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros