<?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: How to handle NULL values in JSL script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7498#M7492</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You very much for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Sep 2013 13:12:25 GMT</pubDate>
    <dc:creator>gerardmcl</dc:creator>
    <dc:date>2013-09-24T13:12:25Z</dc:date>
    <item>
      <title>How to handle NULL values in JSL script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7496#M7490</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am very new to JSL, my background is pl/sql.&lt;/P&gt;
&lt;P&gt;I have an INSERT (see below) to an Oracle table that is failing on some rows that have null values in a few of the columns.&lt;/P&gt;
&lt;P&gt;In Oracle I would just use NVL e.g. NVL(STD_ERROR,0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do this in JSL? In this case it's just column7 that is causing the problem but I would wrap all the columns in the function(?).&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for (i = 1, i &amp;lt;= nrows(dt), i++,
       sql_statement =
"INSERT INTO TBL_COMBINED_STG " ||
"(Y_AXIS, PROD, LOT, TERM, BIAS, ESTIMATE, STD_ERROR, TRATIO, PROB_T) " ||
"VALUES(" ||ULL
"'" || char(column(1)) || "', " ||
"'" || char(column(2)) || "', " ||
"'" || char(column(3)) || "', " ||
"'" || char(column(4)) || "', 0," ||
//char(column(5)) || ", " ||
char(column(6)) || ", " ||
char(column(7)) || ", " ||
char(column(8)) || ", " ||
char(column(9)) || ") ";
 
// JMP will add a commit to the insert statement.
      Execute SQL(dbc, sql_statement);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 18:18:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7496#M7490</guid>
      <dc:creator>gerardmcl</dc:creator>
      <dc:date>2018-06-25T18:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle NULL values in JSL script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7497#M7491</link>
      <description>&lt;P&gt;GerardMcL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For numeric data, the test in JMP is "Is Missing ()".&amp;nbsp; Use the Is Missing function to build your SQL statement,&amp;nbsp; When the Is Missing is true, then use NULL instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, here is one way to do it for small data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would start out with a basic string for the SQL statement and then loop through all values, testing each value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sql statement = beginning stuff || " VALUES("
 
For (I_Counter=1, I_Counter&amp;lt;=NCols(), I_Counter++,
     If (IsMissing(thing I want to test),
          sql statement = sql statement || "NULL, "
     ,
          sql statement = sql statement || Char(Value) || ", "
     )
);
sql statement = Left(SQL Statement, length(sql statement)-2) // removes the final comma
sql statement = sql statement + stuff to close it&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternately, you can take a numeric column and change the Data Type to Character.&amp;nbsp; In this case, missing values will change to strings of length 0.&amp;nbsp; However, I believe that Oracle recommends against the practice of using zero length strings to represent NULL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Michael Haslam&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 18:20:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7497#M7491</guid>
      <dc:creator>michaelhaslam_p</dc:creator>
      <dc:date>2018-06-25T18:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle NULL values in JSL script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7498#M7492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You very much for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 13:12:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7498#M7492</guid>
      <dc:creator>gerardmcl</dc:creator>
      <dc:date>2013-09-24T13:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to handle NULL values in JSL script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7499#M7493</link>
      <description>&lt;P&gt;Here's another approach.&amp;nbsp; Create a new function that acts similarly to Oracle's NVL function with a slight twist - it returns a character string.&amp;nbsp; Notice that I'm returning the empty string "" for your character variables, and returning "NULL" for numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/*
nvl_char: convert number to a character.  If missing return the second value
 
Arguments:
one_value        Numeric value to convert to a character
value_if_null    Character string to return if one_value is missing
*/
nvl_char = Function( {one_value, value_if_null},
      {Default Local},
 
    if (is missing(one_value),
    // then
        value_if_null,
    // else
        char(one_value);
    );
);
 
// Test out the function
nvl_char(123, "NULL");
nvl_char(., "NULL");
nvl_char(., "");
 
for (i = 1, i &amp;lt;= nrows(dt), i++,
       sql_statement =
"INSERT INTO TBL_COMBINED_STG " ||
"(Y_AXIS, PROD, LOT, TERM, BIAS, ESTIMATE, STD_ERROR, TRATIO, PROB_T) " ||
"VALUES(" ||
"'" || nvl_char(column(1)[i], "") || "', " ||
"'" || nvl_char(column(2)[i], "") || "', " ||
"'" || nvl_char(column(3)[i], "") || "', " ||
"'" || nvl_char(column(4)[i], "") || "', 0," ||
//char(column(5)) || ", " ||
nvl_char(column(6)[i], "NULL") || ", " ||
nvl_char(column(7)[i], "NULL") || ", " ||
nvl_char(column(8)[i], "NULL") || ", " ||
nvl_char(column(9)[i], "NULL") || ") ";
 
// JMP will add a commit to the insert statement.
      Execute SQL(dbc, sql_statement);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 18:20:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-handle-NULL-values-in-JSL-script/m-p/7499#M7493</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-06-25T18:20:38Z</dc:date>
    </item>
  </channel>
</rss>

