<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inserting DateTime into SQL Server datetime field (via Proc SQL) in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/754470#M20032</link>
    <description>&lt;P&gt;In my experience more recent SQL Server ODBC drivers do a better job to correctly read or write datetime columns.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 00:51:56 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2021-07-16T00:51:56Z</dc:date>
    <item>
      <title>Inserting DateTime into SQL Server datetime field (via Proc SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/734305#M19905</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question on inserting a datetime, from SAS, into a SQL Server datetime column, using SAS Data Integration Studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The target SQL Server field is a&amp;nbsp; 'datetime'. When inspecting the target table in SAS, I see the values in the target SQL Server table defined with a format of DATETIME22.3, as shown below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="datetimeSQLServer.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57893i8ABDEF5C140A7170/image-size/large?v=v2&amp;amp;px=999" role="button" title="datetimeSQLServer.png" alt="datetimeSQLServer.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the SAS side, I am defining a source field, that is calculated using the DATETIME() function, with a format of DATETIME22.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run an Update transformation to update 'Personnel', the target SQL Server table, I'd like to update the InsertTimeStamp field with the time that the record was updated, by referencing the column that is calculated in SAS using DATETIME(). My proc SQL statement looks like the following (note I've removed the schema name/LIBNAME reference on the Personnel table, the target table).&lt;/P&gt;&lt;PRE&gt;update Personnel
      set 
         DeptCode= (
            select
               UpdatePrimaryDepartment.DeptID length = 32   
                  format = $32.
                  informat = $32.
                  label = 'DeptID'
            from
               work.UpdatePrimaryDepartment as UpdatePrimaryDepartment
            where
               Personnel.PersonID = UpdatePrimaryDepartment.PersonID
         ),
         InsertTimestamp= (
            select
               UpdatePrimaryDepartment.insert_time length = 8   
                  format = DATETIME22.3
                  informat = DATETIME22.3
            from
               work.UpdatePrimaryDepartment as UpdatePrimaryDepartment
            where
               Personnel.PersonID = UpdatePrimaryDepartment.PersonID
         )
      where
          EXISTS (
            select *
            from
               work.UpdatePrimaryDepartment as UpdatePrimaryDepartment
            where
               UpdatePrimaryDepartment.PersonID = Personnel.PersonID
               and UpdatePrimaryDepartment.CheckDepartment = 'X'
         )
   ;
quit;&lt;/PRE&gt;&lt;P&gt;Removing the code to set the InsertTimestamp field works perfectly fine. However, whenever I try to set the InsertTimestamp field, I get the following error message from SAS (which is passed from SQL Server):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: CLI execute error: [SAS][ODBC SQL Server Legacy Driver][SQL Server]Conversion failed when converting date and/or time from character string&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something obvious I am missing with inserting the datetime values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 15:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/734305#M19905</guid>
      <dc:creator>mws1985</dc:creator>
      <dc:date>2021-04-15T15:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting DateTime into SQL Server datetime field (via Proc SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/737298#M19917</link>
      <description>&lt;P&gt;I don't know why this isn't working, but if you activate tracing it may give you some hints.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options msglevel=i sastrace=',,,d' sastraceloc=saslog nostsuffix;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 15:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/737298#M19917</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2021-04-27T15:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting DateTime into SQL Server datetime field (via Proc SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/754354#M20031</link>
      <description>&lt;P&gt;Thanks, Linus. As it turned out, a different driver needed to be installed on our instance of Data Integration Studio for use with SQL Server databases. Once this was done, it worked fine.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 14:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/754354#M20031</guid>
      <dc:creator>mws1985</dc:creator>
      <dc:date>2021-07-15T14:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting DateTime into SQL Server datetime field (via Proc SQL)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/754470#M20032</link>
      <description>&lt;P&gt;In my experience more recent SQL Server ODBC drivers do a better job to correctly read or write datetime columns.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 00:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Inserting-DateTime-into-SQL-Server-datetime-field-via-Proc-SQL/m-p/754470#M20032</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-07-16T00:51:56Z</dc:date>
    </item>
  </channel>
</rss>

