<?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: JSL for SQL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212159#M42469</link>
    <description>&lt;P&gt;If you transpose the tables you can join to itself on t1.row &amp;lt; t2.row.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This script worked for me but assumes 1 row (which I doubt is true, but you could select a single row), I also had to add an ID column to transpose upon and a row_Number.&amp;nbsp; Row number is sorted by the column name so if that doesn't work, I don't know.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DECLARE @colsUnpivot AS NVARCHAR(MAX),
    @query  AS NVARCHAR(MAX)

select @colsUnpivot = stuff((select ','+quotename(C.name)
         from sys.columns as C
         where C.object_id = object_id('[Test].[dbo].[example]') and
               C.name &amp;lt;&amp;gt; 'ID'
         for xml path('')), 1, 1, '')


set @query 
  = 'with t1 AS (select ID, ROW_NUMBER() OVER(ORDER BY name ASC) AS Row#, name, value
from [Test].[dbo].[example]
unpivot
(
    value for name in ('+@colsUnpivot+')
) unpiv), 
t2 AS  (select ID, ROW_NUMBER() OVER(ORDER BY name ASC) AS Row#, name, value
from [Test].[dbo].[example]
unpivot
(
    value for name in ('+@colsUnpivot+')
) unpiv)

SELECT CAST(t1.value AS varchar(14)) + ''_'' + CAST(t2.value AS varchar(14)) AS [concatted]
FROM t1 INNER JOIN t2 ON t1.Row# &amp;lt; t2.Row#
ORDER BY t1.Row# ASC, t2.Row# ASC'&lt;/PRE&gt;
&lt;P&gt;Is there a reason you're doing it in SQL though and not in JMP?&amp;nbsp; Because I find this a LOT easier in JMP (and I feel more robust as well).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nck = nchoosekmatrix(ncols(dt), 2);
mat = dt &amp;lt;&amp;lt; Get As Matrix;
nmat = shape(mat[nck], nrows(nck), 2);
dt_new = New Table("Concatted",
	New Column("Value1", &amp;lt;&amp;lt;Set Values(nmat[0, 1])), 
	New Column("Value2", &amp;lt;&amp;lt;Set Values(nmat[0, 2])), 
	New Column("Concat", &amp;lt;&amp;lt;Formula(char(:Value1)||"_"||char(:Value2))), 
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jun 2019 17:02:51 GMT</pubDate>
    <dc:creator>vince_faller</dc:creator>
    <dc:date>2019-06-06T17:02:51Z</dc:date>
    <item>
      <title>JSL for SQL</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212096#M42463</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;Attached is a script I wrote that accomplishes what I need.&lt;/P&gt;&lt;P&gt;Basically&amp;nbsp;it creates&amp;nbsp;pairs out of sequential (left to right) cells, going from (1,2), (1,3), ..., (1, k), (2, 3), ..., (k-1, k)&lt;/P&gt;&lt;P&gt;Then it stacks them and labels them.&lt;/P&gt;&lt;P&gt;Does anyone know how to accomplish the same&amp;nbsp;in SQL.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;MG&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 13:19:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212096#M42463</guid>
      <dc:creator>GM</dc:creator>
      <dc:date>2019-06-06T13:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: JSL for SQL</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212159#M42469</link>
      <description>&lt;P&gt;If you transpose the tables you can join to itself on t1.row &amp;lt; t2.row.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This script worked for me but assumes 1 row (which I doubt is true, but you could select a single row), I also had to add an ID column to transpose upon and a row_Number.&amp;nbsp; Row number is sorted by the column name so if that doesn't work, I don't know.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DECLARE @colsUnpivot AS NVARCHAR(MAX),
    @query  AS NVARCHAR(MAX)

select @colsUnpivot = stuff((select ','+quotename(C.name)
         from sys.columns as C
         where C.object_id = object_id('[Test].[dbo].[example]') and
               C.name &amp;lt;&amp;gt; 'ID'
         for xml path('')), 1, 1, '')


set @query 
  = 'with t1 AS (select ID, ROW_NUMBER() OVER(ORDER BY name ASC) AS Row#, name, value
from [Test].[dbo].[example]
unpivot
(
    value for name in ('+@colsUnpivot+')
) unpiv), 
t2 AS  (select ID, ROW_NUMBER() OVER(ORDER BY name ASC) AS Row#, name, value
from [Test].[dbo].[example]
unpivot
(
    value for name in ('+@colsUnpivot+')
) unpiv)

SELECT CAST(t1.value AS varchar(14)) + ''_'' + CAST(t2.value AS varchar(14)) AS [concatted]
FROM t1 INNER JOIN t2 ON t1.Row# &amp;lt; t2.Row#
ORDER BY t1.Row# ASC, t2.Row# ASC'&lt;/PRE&gt;
&lt;P&gt;Is there a reason you're doing it in SQL though and not in JMP?&amp;nbsp; Because I find this a LOT easier in JMP (and I feel more robust as well).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nck = nchoosekmatrix(ncols(dt), 2);
mat = dt &amp;lt;&amp;lt; Get As Matrix;
nmat = shape(mat[nck], nrows(nck), 2);
dt_new = New Table("Concatted",
	New Column("Value1", &amp;lt;&amp;lt;Set Values(nmat[0, 1])), 
	New Column("Value2", &amp;lt;&amp;lt;Set Values(nmat[0, 2])), 
	New Column("Concat", &amp;lt;&amp;lt;Formula(char(:Value1)||"_"||char(:Value2))), 
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:02:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212159#M42469</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-06-06T17:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: JSL for SQL</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212172#M42470</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2610"&gt;@vince_faller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Your JSL&amp;nbsp;approach is defnitley more slick than the double for loops.&lt;/P&gt;&lt;P&gt;Much appreciate for showing the nchoosekmatrix function!&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;MG&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:40:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-for-SQL/m-p/212172#M42470</guid>
      <dc:creator>GM</dc:creator>
      <dc:date>2019-06-06T17:40:59Z</dc:date>
    </item>
  </channel>
</rss>

