<?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 sql json data in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/sql-json-data/m-p/1612174#M596905</link>
    <description>&lt;P&gt;I am working with a MySQL Server db that contains JSON data. I am trying to get data from the JSON portion to pivot into a column AND to extract data from there as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My JSON field is [AnswersJson]:&amp;nbsp;[{"AnswerPart":null,"AnswerColumn":null,"AnswerText":"a","AnswerOther":null,"AnswerExportValue":null,"AnswerComment":null}]&amp;nbsp; where I need to pull '$.AnswerText', sometimes 'AnswerOther', and sometimes '$.AnswerExportValue'&lt;/P&gt;&lt;P&gt;The field I want to turn into a column heading is [Survey].&lt;/P&gt;&lt;P&gt;There is another table that has a JSON field, [JsonData] which has some elements for a person (FirstName, LastName, Generation, Age, etc). This is where the subquery comes into play as I was able to make work within SQL Server. Each time I add to data load editor, a good portion does not get recognized due to the (') and cannot figure out thogh a straight copy and paste does not result in anything pulled as it does in SQL Server.&lt;/P&gt;&lt;P&gt;I have 18 different survey questions that come through, so doing a constant if(SurveyNumber=1, [SurveyQuestion]) looks ugly as well inefficient if a survey text is updated.&lt;/P&gt;&lt;P&gt;I would love it if the result could show:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;SurveyQuestion1&lt;/TD&gt;&lt;TD&gt;SurveyQuestion2&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;SurveyQuestion&lt;/SPAN&gt;3&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;SurveyQuestion&lt;/SPAN&gt;4&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt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/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;where SurveyQuestion1 is the first question with the associated AnswerText, SurveyQuestion2 is the second question and AnswerText all the way through to question 18.&lt;/P&gt;&lt;P&gt;Is there anything that can do this?&lt;/P&gt;&lt;P&gt;Example code is below that I have tested with in various ways.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL&lt;BR /&gt;SET NOCOUNT ON&lt;BR /&gt;DECLARE&lt;BR /&gt;@cols AS NVARCHAR(MAX),&lt;BR /&gt;@query AS NVARCHAR(MAX)&lt;BR /&gt;SELECT&lt;BR /&gt;let @cols = STUFF((SELECT distinct ',' + QUOTENAME(Survey) FROM [SurveyQuestion].[dbo].[QuestionDetails]).value('.', 'NVARCHAR(MAX)'),1,1,'')&lt;BR /&gt;let @query = (SELECT [Responder_Id],CREATED,FirstName,LastName,Age2,Generation, ' + @cols + '&lt;BR /&gt;FROM&lt;BR /&gt;(SELECT&lt;BR /&gt;[Responder_Id]&lt;BR /&gt;,DETAILS.[CreateDateTime] AS CREATED&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.FirstName'') AS FirstName&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.LastName'') AS LastName&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.Age'') AS Age2&lt;BR /&gt;--,null AS Generation&lt;BR /&gt;,[Survey]&lt;BR /&gt;,[AnswersJson]&lt;BR /&gt;FROM&lt;BR /&gt;[SurveyQuestion].[dbo].[QuestionDetails] AS DETAILS&lt;BR /&gt;INNER JOIN Responder AS RESPONDER ON RESPONDER.Id = DETAILS.Responder_Id&lt;BR /&gt;&lt;BR /&gt;) x&lt;BR /&gt;pivot&lt;BR /&gt;(max([AnswersJson])&lt;BR /&gt;for[Survey] in (' + @cols + ')) p&lt;/P&gt;&lt;P&gt;execute sp_executesql @query;&lt;/P&gt;&lt;P&gt;Help me obi wan Kenobi, you are my only hope&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 20:16:23 GMT</pubDate>
    <dc:creator>SonOfJeffGoldblum</dc:creator>
    <dc:date>2024-11-16T20:16:23Z</dc:date>
    <item>
      <title>sql json data</title>
      <link>https://community.qlik.com/t5/QlikView/sql-json-data/m-p/1612174#M596905</link>
      <description>&lt;P&gt;I am working with a MySQL Server db that contains JSON data. I am trying to get data from the JSON portion to pivot into a column AND to extract data from there as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My JSON field is [AnswersJson]:&amp;nbsp;[{"AnswerPart":null,"AnswerColumn":null,"AnswerText":"a","AnswerOther":null,"AnswerExportValue":null,"AnswerComment":null}]&amp;nbsp; where I need to pull '$.AnswerText', sometimes 'AnswerOther', and sometimes '$.AnswerExportValue'&lt;/P&gt;&lt;P&gt;The field I want to turn into a column heading is [Survey].&lt;/P&gt;&lt;P&gt;There is another table that has a JSON field, [JsonData] which has some elements for a person (FirstName, LastName, Generation, Age, etc). This is where the subquery comes into play as I was able to make work within SQL Server. Each time I add to data load editor, a good portion does not get recognized due to the (') and cannot figure out thogh a straight copy and paste does not result in anything pulled as it does in SQL Server.&lt;/P&gt;&lt;P&gt;I have 18 different survey questions that come through, so doing a constant if(SurveyNumber=1, [SurveyQuestion]) looks ugly as well inefficient if a survey text is updated.&lt;/P&gt;&lt;P&gt;I would love it if the result could show:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;SurveyQuestion1&lt;/TD&gt;&lt;TD&gt;SurveyQuestion2&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;SurveyQuestion&lt;/SPAN&gt;3&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;SurveyQuestion&lt;/SPAN&gt;4&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;SurveyQuestion&lt;/SPAN&gt;5&lt;/TD&gt;&lt;TD&g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TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;where SurveyQuestion1 is the first question with the associated AnswerText, SurveyQuestion2 is the second question and AnswerText all the way through to question 18.&lt;/P&gt;&lt;P&gt;Is there anything that can do this?&lt;/P&gt;&lt;P&gt;Example code is below that I have tested with in various ways.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL&lt;BR /&gt;SET NOCOUNT ON&lt;BR /&gt;DECLARE&lt;BR /&gt;@cols AS NVARCHAR(MAX),&lt;BR /&gt;@query AS NVARCHAR(MAX)&lt;BR /&gt;SELECT&lt;BR /&gt;let @cols = STUFF((SELECT distinct ',' + QUOTENAME(Survey) FROM [SurveyQuestion].[dbo].[QuestionDetails]).value('.', 'NVARCHAR(MAX)'),1,1,'')&lt;BR /&gt;let @query = (SELECT [Responder_Id],CREATED,FirstName,LastName,Age2,Generation, ' + @cols + '&lt;BR /&gt;FROM&lt;BR /&gt;(SELECT&lt;BR /&gt;[Responder_Id]&lt;BR /&gt;,DETAILS.[CreateDateTime] AS CREATED&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.FirstName'') AS FirstName&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.LastName'') AS LastName&lt;BR /&gt;,JSON_VALUE(JsonData, ''$.Age'') AS Age2&lt;BR /&gt;--,null AS Generation&lt;BR /&gt;,[Survey]&lt;BR /&gt;,[AnswersJson]&lt;BR /&gt;FROM&lt;BR /&gt;[SurveyQuestion].[dbo].[QuestionDetails] AS DETAILS&lt;BR /&gt;INNER JOIN Responder AS RESPONDER ON RESPONDER.Id = DETAILS.Responder_Id&lt;BR /&gt;&lt;BR /&gt;) x&lt;BR /&gt;pivot&lt;BR /&gt;(max([AnswersJson])&lt;BR /&gt;for[Survey] in (' + @cols + ')) p&lt;/P&gt;&lt;P&gt;execute sp_executesql @query;&lt;/P&gt;&lt;P&gt;Help me obi wan Kenobi, you are my only hope&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 20:16:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/sql-json-data/m-p/1612174#M596905</guid>
      <dc:creator>SonOfJeffGoldblum</dc:creator>
      <dc:date>2024-11-16T20:16:23Z</dc:date>
    </item>
  </channel>
</rss>

