title: Why can't I insert data to my table?
body: <p>I created a table using this</p>
  
  <pre><code>IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[DimRegion]') AND type in (N'U'))
  DROP TABLE [DimRegion]
  Go
  Create Table DimRegion
  
  (RegionViewKey int NOT NULL identity Primary Key,                              
  RegionView          varchar(10),
  RegionViewCode      varchar(10),
  ActiveYear              smallint,
  SublocationString       varchar(7)NULL,
  SubLocationCode     char(10)NOT NULL,
  LocationCode            char(10)NULL,
  RegionCode          char(10)NULL,
  RegionGrpCode           char(10)NULL,
  DivisionCode            char(10)NOT NULL,
  DivisionGrpCode     char(10)NULL,
  SubLocationDescription      char(50)NULL,
  LocationDescription     char(50)NULL,
  RegionDescription       char(50)NULL,
  RegionGrpDescription        char(50)NULL,
  DivisionDescription     char(50)NULL,
  DivisionGrpDescription      char(50)NULL)
  </code></pre>
  
  <p>And I inserted data using this script</p>
  
  <pre><code>insert into DWResourceTask.dbo.DimRegion --(2013)
  
  Select
  'Region1' as RegionView,
  'R1' as RegionViewCode,
  '2013' as ActiveYear, 
  sl.sublocationstring, 
  sl.subLocationCode, 
  l.locationcode,
  r.regioncode,
  rg.RegionGrpCode,  
  d.DivisionCode, 
  dg.DivisionGrpCode,
  sl.SubLocationDescription, 
  l.LocationDescription, 
  r.regiondescription,
  rg.RegionGrpDescription, 
  d.divisionDescription, 
  dg.DivisionGrpDescription
  from SCSubLocation sl, 
  SCLocation l, 
  SCRegion r, 
  SCRegionGrp rg,
  SCDivision d,
  SCDivisionGrp dg
  where l.LocationCode = sl.LocationCode
  and r.RegionCode = l.RegionCode
  and r.RegionGrpCode = rg.RegionGrpCode
  and d.divisioncode = rg.divisioncode
  and d.divisiongrpcode = dg.divisiongrpcode
  </code></pre>
  
  <p>But when I created this script below where it would only insert new and latest data, it gives me an error such as </p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 33<br>
    Incorrect syntax near 'R1'.</p>
  </blockquote>
  
  <p>Script:</p>
  
  <pre><code>insert into DWResourceTask.dbo.DimRegion --(2013)
  
  Select
  'Region1' as RegionView,
  'R1' as RegionViewCode,
  '2013' as ActiveYear, 
  sl.sublocationstring, 
  sl.subLocationCode, 
  l.locationcode,
  r.regioncode,
  rg.RegionGrpCode,  
  d.DivisionCode, 
  dg.DivisionGrpCode,
  sl.SubLocationDescription, 
  l.LocationDescription, 
  r.regiondescription,
  rg.RegionGrpDescription, 
  d.divisionDescription, 
  dg.DivisionGrpDescription
  from SCSubLocation sl, 
  SCLocation l, 
  SCRegion r, 
  SCRegionGrp rg,
  SCDivision d,
  SCDivisionGrp dg
  where l.LocationCode = sl.LocationCode
  and r.RegionCode = l.RegionCode
  and r.RegionGrpCode = rg.RegionGrpCode
  and d.divisioncode = rg.divisioncode
  and d.divisiongrpcode = dg.divisiongrpcode
  and not exists(select * from DWResourceTask.dbo.DimRegion x
                    where(Region1=x.RegionView
                          R1=x.RegionViewCode
                          2013=x.ActiveYear 
                          sl.sublocationstring=x.sublocationstring
                          sl.subLocationCode=x.subLocationCode
                           l.locationcode=x.locationcode
                           r.regioncode=x.regioncode
                          rg.RegionGrpCode=x.RegionGrpCode
                           d.DivisionCode=x.DivisionCode
                          dg.DivisionGrpCode=x.DivisionGrpCode
                          sl.SubLocationDescription=x.SubLocationDescription
                           l.LocationDescription=x.LocationDescription 
                           r.regiondescription=x.regiondescription
                          rg.RegionGrpDescription=x.RegionGrpDescription
                           d.divisionDescription=x.divisionDescription 
                          dg.DivisionGrpDescription=x.DivisionGrpDescription)
                          )
  </code></pre>
  
  <p>How do I fix this script on top where it only inserts latest data</p>