查表的数据来拼接insert语句的写法2

select 'INSERT INTO dbo.sfa_t_TPlaVisitPlan
        ( usernumber ,
          UserName ,
          VisitDate ,
          ExecuteStatus ,
          CheckStatus ,
          WorkTips ,
          CheckContent ,
          Remark ,
          EnterpriseNumber ,
          CreateOp ,
          CreateTime ,
          UpdateOp ,
          UpdateTime ,
          CheckOp ,
          CheckTime,
    a_id
        )
VALUES  ( ',UserNumber,' ,
          ''',ltrim(rtrim(UserName)),''',   
   ''' ,VisitDate,''',
          ',ExecuteStatus,' ,
          ',CheckStatus,' ,
          ',WorkTips,' ,
          ',CheckContent,' ,
          ',Remark,' ,
          ',EnterpriseNumber,' ,
          ',CreateOp,' ,
          ',CreateTime,' ,
          ',UpdateOp,' ,
          ',UpdateTime,' ,
          ',CheckOp,' ,
          ',CheckTime,'  ,',VisitPlanID,'
        )
        '
 from xw_dl_1007724.dbo.sfa_t_tplavisitplan where visitplanid >= 12951

你可能感兴趣的:(sql,server)