SQLTeam.com | Weblogs | Forums

Add rows to table


#1

insert into dbo.TV0VBIJLAGE (SEK_DOSSIER, sek_bijlage, SEK_SOORTBIJLAGE, MAP,bijlage)
values (688140, 100, 12085, '\intranet\dfsroot\Data\Cevi\Adm\tv0\besluiten', 45017_B2015121.pdf )

where sek_dossier is a select (below)

select SEK_DOSSIER, EIGREF_JAAR, EIGREF_NUMMER, from dbo.CV1_RODOSSIERBIS where REGISTERJAAR > 2014 AND BESLIS_GEM like 'vergunning' and D_BESLIS_GEM > '2016-01-01' AND CODE_PROCEDURE like 'ASTVER2009' order by SEK_DOSSIER

bijlage is select '45017_B' + rtrim(eigref_jaar) + rtrim(convert(char(4),EIGREF_Nummer)) + '.pdf' from dbo.CV1_RODOSSIERBIS where REGISTERJAAR > 2014 AND BESLIS_GEM like 'vergunning' and D_BESLIS_GEM > '2016-01-01' AND CODE_PROCEDURE like 'ASTVER2009' order by SEK_DOSSIER

How can i in one statement insert the selected rows?


#2

First check that this gives you the rows you expect:

select sek_dossier
      ,sek_bijlage
      ,sek_soortbijlage
      ,map
      ,'45017_B'
      +rtrim(eigref_jaar)
      +rtrim(convert(char(4),EIGREF_Nummer))
      +'.pdf'
       as bijlage
  from dbo.cv1_rodossierbis
 where registerjaar>2014
   and beslis_gem='vergunning'
   and d_beslis_gem>cast('2016-01-01' as date)
   and code_procedure='ASTVER2009'
;

If it does, put this infront of the select:

insert into dbo.tb0vbijlage (sek_dossier
                            ,sek_bijlage
                            ,sek_soortbijlage
                            ,map
                            ,bijlage
                            )

#3

works perfectly