I have created a view from two tables morning shift and night shift employees
My view looks like this:
USE Employees
GO
CREATE VIEW EmployeesShift
SELECT MEID AS ID, MEName AS Name, Status, Address
FROM MorningEmployees
UNION ALL
SELECT NEID AS ID, NEName AS Name, Status, Address
FROM NightEmployees
The resulting table looks like this
However I want the values of ID field to look like this
Can Anyone help please?
https://docs.microsoft.com/en-us/sql/t-sql/functions/row-number-transact-sql?view=sql-server-ver15
You can use a windowing function to generate a unique ID for every row on the fly
select * from (
SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 10000)) AS id FROM dbo.EmployeesShift) a
order by a.id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.