<?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 do I assign a SQL query result to a variable? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843245#M101698</link>
    <description>&lt;P&gt;Thank you for the response! I tried editing it to what you shared and when I do a "Show" I am getting this:&lt;/P&gt;&lt;P&gt;vLCL = DataTable("SQL Results 799");&lt;/P&gt;&lt;P&gt;So I think my problem is that I am not actually assigning the result of the query to vLCL as a numeric value? Do you know how I can correct this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
    <pubDate>Thu, 20 Feb 2025 17:54:01 GMT</pubDate>
    <dc:creator>JaneCuthbertson</dc:creator>
    <dc:date>2025-02-20T17:54:01Z</dc:date>
    <item>
      <title>How do I assign a SQL query result to a variable?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843226#M101695</link>
      <description>&lt;P&gt;Hello! I am new to JMP/JSL scripting and am having some trouble figuring things out. I feel like what I am trying to do should be very simple but nothing seems to be working as I would expect and google is failing me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do: I have a simple stored procedure that just returns a control limit value from our SQL database based on a few parameters I pass to it. I am then trying to assign that value to a Levey Jennings control limit for a column. The code below is as far as I have gotten.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code is outputting a table with my desired value.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Get limit value
LimitType = "Control";
LimitLevel = "Lower";
utagID = "6720";
vLCL = open database(
	"Driver={SQL Server};Server=FC-SQL-P\PROD;Database=ctc_config;Trusted_Connection=yes",
	"cus_sp_taglimits
		@LimitType = " || LimitType || ",
		@LimitLevel = " || LimitLevel || ",
		@utagid = '" || utagID || "'"
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am then trying to use the value of "vLCL" and apply it to a different tables column properties.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Change column property
Data Table( "testTable" ):testColumn &amp;lt;&amp;lt; Set Property(
	"Control Limits",
	{Levey Jennings( LCL( vLCL ) )}
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The script above works fine when I replace "vLCL" with a number.&lt;/P&gt;&lt;P&gt;Where I think I am getting stuck is, how do I use my SQL result as an actual variable? Is there a way to query a value directly into a variable instead of pulling it into a new table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on this would be greatly appreciated! Thank you in advance!!&lt;/P&gt;&lt;P&gt;-Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 17:25:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843226#M101695</guid>
      <dc:creator>JaneCuthbertson</dc:creator>
      <dc:date>2025-02-20T17:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a SQL query result to a variable?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843236#M101696</link>
      <description>&lt;P&gt;&lt;STRONG&gt;If&lt;/STRONG&gt; your vLCL has what you are looking for, you just need to evaluate it, here is one option on how to do it with column properties like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(EvalExpr(
	Data Table("testTable"):testColumn &amp;lt;&amp;lt; Set Property(
		"Control Limits",
		{Levey Jennings(LCL(Expr(vLCL)))}
	);	
));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are unsure what is stored to vLCL you can for example add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;show(vLCL);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;after the query and verify it has what you are looking for&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 17:36:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843236#M101696</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-20T17:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a SQL query result to a variable?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843245#M101698</link>
      <description>&lt;P&gt;Thank you for the response! I tried editing it to what you shared and when I do a "Show" I am getting this:&lt;/P&gt;&lt;P&gt;vLCL = DataTable("SQL Results 799");&lt;/P&gt;&lt;P&gt;So I think my problem is that I am not actually assigning the result of the query to vLCL as a numeric value? Do you know how I can correct this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 17:54:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843245#M101698</guid>
      <dc:creator>JaneCuthbertson</dc:creator>
      <dc:date>2025-02-20T17:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a SQL query result to a variable?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843247#M101699</link>
      <description>&lt;P&gt;Depends on your resulting table which vLCL holds. Data table subscripting might be enough, and sometimes you might have to combine it with &amp;lt;&amp;lt; get rows where. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is very basic example of data table subscripting which takes values from first row from LSL and USL columns&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("LSL", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column("USL", Numeric, "Continuous", Format("Best", 12), Set Values([2]))
);

my_lsl = dt[1, "LSL"];
my_usl = dt[1, "USL"];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Data table subscripting" uid="21013" url="https://community.jmp.com/t5/Uncharted/Data-table-subscripting/m-p/21013#U21013" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 17:57:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843247#M101699</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-20T17:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a SQL query result to a variable?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843253#M101702</link>
      <description>&lt;P&gt;Oh my gosh thank you this is exactly what I was missing!&lt;/P&gt;&lt;P&gt;I adjusted my code to the following and it is working perfectly!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Get limit value -- returns a new table with a  single value
LimitType = "Control";
LimitLevel = "Lower";
utagID = "6720";
tblLCL = open database(
	"Driver={SQL Server};Server=FC-SQL-P\PROD;Database=ctc_config;Trusted_Connection=yes",
	"cus_sp_taglimits
		@LimitType = " || LimitType || ",
		@LimitLevel = " || LimitLevel || ",
		@utagid = '" || utagID || "'"
);
//assign table value to variable
vLCL = tblLCL[1,1];
// Change column property
Eval(EvalExpr(
	Data Table( "testTable" ):testColumn &amp;lt;&amp;lt; Set Property(
		"Control Limits",
		{Levey Jennings( LCL( Expr(vLCL) ) )}
	);
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you thank you thank you!&lt;/P&gt;&lt;P&gt;-Jane&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 18:11:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-assign-a-SQL-query-result-to-a-variable/m-p/843253#M101702</guid>
      <dc:creator>JaneCuthbertson</dc:creator>
      <dc:date>2025-02-20T18:11:22Z</dc:date>
    </item>
  </channel>
</rss>

