CREATE TABLE dbo.Ids
(
DlId nvarchar(32) NOT NULL PRIMARY KEY,
DlIdGUID uniqueidentifier NOT NULL
)
INSERT INTO dbo.Ids
(DlId, REPLACE(DlId, DlId, newid()))
(SELECT DISTINCT TOP 5 DriversLic FROM Student.dbo.StudDL
WHERE DlId LIKE '%345%')
错误说
'('
附近的语法不正确
答案 0 :(得分:0)
插入匹配的DriversLic
和新GUID;
INSERT INTO dbo.Ids (DlId, DlIdGUID)
(SELECT DISTINCT TOP 5 DriversLic, NEWID()
FROM Student.dbo.StudDL
WHERE DlId LIKE '%345%')
使用DISTINCT
:
;with T(DriversLic) as (
select distinct top 5 DriversLic from StudDL
)
insert Ids
select DriversLic, NEWID() from T