<?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: Oracle Passthrough to Snowflake Passthrough in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Oracle-Passthrough-to-Snowflake-Passthrough/m-p/663648#M198153</link>
    <description>&lt;P&gt;In Oracle the data types Date and Timestamp both store DateTime values. The only difference is that Timestamp can also store fractional seconds.&lt;/P&gt;
&lt;P&gt;The TRUNC() in your Oracle SQL simply aligns the Date value to the beginning of the day - but it remains a DateTime value (and you could also just have used a date string only for you to_date() function to get the same result).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the snowflake documentation &lt;A href="https://docs.snowflake.com/en/sql-reference/data-types-datetime.html" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;the data type Date is more like a SAS Date value and Timestamp data types are more like SAS DateTime values. Furthermore the documentation &lt;A href="https://docs.snowflake.com/en/sql-reference/functions/to_date.html" target="_self"&gt;here&lt;/A&gt; tells us that the To_Date() function in snowflake will only use the date portion of a DateTime string for conversion. ...So I guess you'll end up comparing a snowflake Timestamp with a snowflake Date value and the result is similar to comparing a SAS DateTime to a SAS Date value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is quite good documentation available:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.snowflake.com/en/user-guide/date-time-examples.html#using-dates-and-timestamps" target="_self"&gt;Using Dates and Timestamps&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.snowflake.com/en/sql-reference/functions-date-time.html#date-time-functions" target="_self"&gt;Date &amp;amp; Time Functions&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May be the least code-change as compared to your Oracle SQL would be something like:&lt;/P&gt;
&lt;PRE&gt;to_date(o.order_timestamp) &amp;gt;= (to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy')&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Alternatively something like below should also work.&lt;/P&gt;
&lt;PRE&gt;o.order_timestamp &amp;gt;= date_trunc('DAY', TO_TIMESTAMP_NTZ(%str(%'&amp;amp;Startdate%')),'ddmonyyyy'))&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jun 2020 23:11:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-06-19T23:11:05Z</dc:date>
    <item>
      <title>Oracle Passthrough to Snowflake Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Oracle-Passthrough-to-Snowflake-Passthrough/m-p/663595#M198119</link>
      <description>&lt;P&gt;i am having some issues converting some passthrough code from Oracle to Snowflake for date and time intervals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The original code form oracle passthrough is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;and (( o.order_timestamp &amp;gt;= trunc(to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy') and 
       o.order_timestamp &amp;lt; to_date(to_char(to_date(%str(%'&amp;amp;Startdate%'),'ddmonyyyy'),'yyyymmdd')||decode(%str(%'&amp;amp;interval%')||'00','240000','235959',%str(%'&amp;amp;interval%')||'00'),'yyyymmddhh24miss') or
       o.order_timestamp &amp;gt;= trunc(to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy')-364 and  
o.order_timestamp &amp;lt; to_date(to_char(to_date(%str(%'&amp;amp;Startdate%'),'ddmonyyyy')-364,'yyyymmdd')||decode(%str(%'&amp;amp;interval%')||'00','240000','235959',%str(%'&amp;amp;interval%')||'00'),'yyyymmddhh24miss')))
&lt;/PRE&gt;
&lt;P&gt;i took of the trunc statements like this:&lt;/P&gt;
&lt;PRE&gt;and (( o.order_timestamp &amp;gt;= (to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy') and 
       o.order_timestamp &amp;lt; to_date(to_char(to_date(%str(%'&amp;amp;Startdate%'),'ddmonyyyy'),'yyyymmdd')||decode(%str(%'&amp;amp;interval%')||'00','240000','235959',%str(%'&amp;amp;interval%')||'00'),'yyyymmddhh24miss') or
       o.order_timestamp &amp;gt;= (to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy')-364 and  
o.order_timestamp &amp;lt; to_date(to_char(to_date(%str(%'&amp;amp;Startdate%'),'ddmonyyyy')-364,'yyyymmdd')||decode(%str(%'&amp;amp;interval%')||'00','240000','235959',%str(%'&amp;amp;interval%')||'00'),'yyyymmddhh24miss&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The parameter code looks like this:&lt;/P&gt;
&lt;PRE&gt;call symput("Startdate",put("&amp;amp;START_DATE"d,yymmdd10.));
  call symput("Begindate",put("&amp;amp;START_DATE"d,yymmdd10.));
  call symput("Enddate",put("&amp;amp;START_DATE"d,yymmdd10.));&lt;/PRE&gt;
&lt;P&gt;When i ran the project with the modified date code, i received no errors and a blank page.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From there i tried my simple date code just to see if was that part of the code was truly the issue:&lt;/P&gt;
&lt;PRE&gt;and o.order_timestamp &amp;gt;= dateadd(dd,-0,%str(%')&amp;amp;Startdate%str(%'))
  and o.order_timestamp &amp;lt;= dateadd(dd,+1,%str(%')&amp;amp;Startdate%str(%'))&lt;/PRE&gt;
&lt;P&gt;When i replaced the date code with this it worked perfectly and i was able to see all my orders for the previous day.&amp;nbsp; The issue is those two DECODE statements are required here.&amp;nbsp; There are several other pieces to this code and i am doing the conversion for them but i can't figure out the right syntax to make it work.&amp;nbsp; I don't likely care what i use in the end as long as it gives me the interval data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone please help with the syntax... i am been working on this for 3 hours now and am just beating my head.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Dean&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 20:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Oracle-Passthrough-to-Snowflake-Passthrough/m-p/663595#M198119</guid>
      <dc:creator>D_Z_</dc:creator>
      <dc:date>2020-06-19T20:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle Passthrough to Snowflake Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Oracle-Passthrough-to-Snowflake-Passthrough/m-p/663648#M198153</link>
      <description>&lt;P&gt;In Oracle the data types Date and Timestamp both store DateTime values. The only difference is that Timestamp can also store fractional seconds.&lt;/P&gt;
&lt;P&gt;The TRUNC() in your Oracle SQL simply aligns the Date value to the beginning of the day - but it remains a DateTime value (and you could also just have used a date string only for you to_date() function to get the same result).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the snowflake documentation &lt;A href="https://docs.snowflake.com/en/sql-reference/data-types-datetime.html" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;the data type Date is more like a SAS Date value and Timestamp data types are more like SAS DateTime values. Furthermore the documentation &lt;A href="https://docs.snowflake.com/en/sql-reference/functions/to_date.html" target="_self"&gt;here&lt;/A&gt; tells us that the To_Date() function in snowflake will only use the date portion of a DateTime string for conversion. ...So I guess you'll end up comparing a snowflake Timestamp with a snowflake Date value and the result is similar to comparing a SAS DateTime to a SAS Date value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is quite good documentation available:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.snowflake.com/en/user-guide/date-time-examples.html#using-dates-and-timestamps" target="_self"&gt;Using Dates and Timestamps&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.snowflake.com/en/sql-reference/functions-date-time.html#date-time-functions" target="_self"&gt;Date &amp;amp; Time Functions&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May be the least code-change as compared to your Oracle SQL would be something like:&lt;/P&gt;
&lt;PRE&gt;to_date(o.order_timestamp) &amp;gt;= (to_date(%str(%'&amp;amp;Startdate%')),'ddmonyyyy')&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Alternatively something like below should also work.&lt;/P&gt;
&lt;PRE&gt;o.order_timestamp &amp;gt;= date_trunc('DAY', TO_TIMESTAMP_NTZ(%str(%'&amp;amp;Startdate%')),'ddmonyyyy'))&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 23:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Oracle-Passthrough-to-Snowflake-Passthrough/m-p/663648#M198153</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-19T23:11:05Z</dc:date>
    </item>
  </channel>
</rss>

