Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Sorting update query

$
0
0

Hello,

I have an existing table that i want to copy in a new table. But in the new table i want only the first following order. So below what i do the query works when i delete the last line (order by). But i need this because i only want to select the following orderNo

UPDATE TOP (1) [ SERVER2 ]. [DATABASE2].[dbo].[NextOrder]
SET   order_number = C.OrderNo
FROM [ SERVER2 ].[ DATABASE2 ].[dbo].[NextOrder] P
      INNER JOIN  [ SERVER1 ].[DATABASE1].[dbo].[Orders] C
ON C.Resource = P.ResourcesID
where [StartTime] >= CURRENT_TIMESTAMP and Resource = 5

order by [StartTime]


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>