我有以下SQL查询,我试图将数据插入测试表,但我还有另一个要求,我需要插入员工编号和他/她的名字。
实施例 名字:71853-osama
我的问题是,如何将两个值插入一个属性 我试过这个
badgeno +'-'+ convert(nvarchar(100),cEmpname) as cEmpname
但它无效
insert into PT (
[FirstName]
,[LastName]
,[FirmID]
,[Note]
,[City]
,[ThirdPartyId]
,[RegisteredBy]
,[Registered]
,[LastUpdatedBy]
,[LastUpdated]
)
SELECT distinct
convert(nvarchar(100),cEmpname) as cEmpname
,convert(nvarchar(100),cJobTitle) as cJobTitle
,'2' as FirmID
,convert(nvarchar(500),sort1) as sort1
,convert(nvarchar(255),cnationality) as cnationality
, badgeno as 'ThirdPartyId'
,'admin' as RegisteredBy
,CURRENT_TIMESTAMP as Registered
,'admin' as LastUpdatedBy
, CURRENT_TIMESTAMP as LastUpdated
FROM [TrailBlazerNG].[dbo].[payper] where lactive = '1'
and not exists ( select 1 from PT where payper.badgeno = PT.ThirdPartyId)
答案 0 :(得分:0)
请尝试以下。
insert into PT ([FirstName],[FirmID],[Note],[City],[ThirdPartyId],[RegisteredBy],[Registered],[LastUpdatedBy],[LastUpdated])
SELECT distinct
convert(nvarchar(100),badgeno)+'-'+convert(nvarchar(100),cEmpname) as cEmpname
,convert(nvarchar(100),cJobTitle) as cJobTitle
,'2' as FirmID
,convert(nvarchar(500),sort1) as sort1
,convert(nvarchar(255),cnationality) as cnationality
, badgeno as 'ThirdPartyId'
,'admin' as RegisteredBy
,CURRENT_TIMESTAMP as Registered
,'admin' as LastUpdatedBy
, CURRENT_TIMESTAMP as LastUpdated
FROM [TrailBlazerNG].[dbo].[payper] where lactive = '1'
and not exists ( select 1 from PT where payper.badgeno = PT.ThirdPartyId)