4 Replies Latest reply on Oct 7, 2014 11:42 AM by Matt Lutton

    Quotation marks for fields in converted Custom SQL query

    Ariel Ortiz

      Hello folks,

      I'm getting quotation marks (instead of square brackets) in my custom SQL queries in Tableau Desktop 8.2.2.

      I'm attaching an example and let me provide you with the steps I follow to get results.

       

      1. I add the tables I need and build joins in the graphical interface for data connections.

      2. Go to the Data menu at the top and select Convert to Custom SQL

      3. I get something similar to what is attached.

       

      Callouts:

      1. The query works just fine once i remove unnecessary fields and set filters for the data.

      2. I am unable to concatenate fields as if I use something like "field1"+ " " +"field2" it keeps saying that there is no name for the " " field between the + signs.

      3. Accordingly with Help info and some other folks in the forum the correct syntax is [field1]+" "+[field2], assuming i need a single space between the two fields, but changing to brackets doesn't work either.

       

      Would you provide some clarification? I'm testing this software towards buying it for our analytic department, but this is becoming challenging.

       

      Thanks

      Ariel

        • 1. Re: Quotation marks for fields in converted Custom SQL query
          Shawn Wallwork

          Ariel welcome to the forums! Here's your SQL:

           

          SELECT "table1"."field1" AS "field 1",

            "table1"."field2" AS "field 2",

            "table2"."field1" AS "table2_field1"

          FROM "DB1"."TABLE1" "table1"

           

          Assuming a MS SQL flavor of SQL I think your query will be:

           

          SELECT table1.field1 AS [field 1]

               , table1.field2 AS [field 2]

               , table2.field1 AS table2_field1

          FROM DB1.TABLE1 table1

           

          But you are calling a field from a table2 table that you're not defining, so even this will fail. Comment that one out and see if it runs.

           

          --Shawn

          • 2. Re: Quotation marks for fields in converted Custom SQL query
            Ariel Ortiz

            Let me try to be more clear.

            The query works with the quotations.

            The focus point here is that Tableau is generating those quotation marks when you try to convert the connection query to a custom SQL one by using Tableau's Convert to Custom SQL feature in the Connect to Data window.

             

            Attaching screenshotTableau Convert to Custom SQL.jpg

            • 3. Re: Quotation marks for fields in converted Custom SQL query
              Shawn Wallwork

              Sorry, I'm still unclear as to what it is you are trying to accomplish? Maybe someone else gets what you are after.

               

              Cheers,

               

              --Shawn

              • 4. Re: Quotation marks for fields in converted Custom SQL query
                Matt Lutton

                You can concatenate the fields after pulling the data into Tableau - what resources were you looking at that showed field concatenation in Custom SQL (only asking so I can try to understand what you're basing your information on -- if you've been using specific links or threads to guide you, just include those links within this thread somewhere)?  Basically, I am looking for what you're referring to when you stated:

                 

                3. Accordingly with Help info and some other folks in the forum the correct syntax is [field1]+" "+[field2], assuming i need a single space between the two fields, but changing to brackets doesn't work either.


                My guess is that whatever you were looking at was referring to concatenating two String fields inside Tableau, AFTER connecting to data.  The syntax above would work inside a Calculated Field; I'm not sure about doing the same inside Custom SQL.  If you can provide the source of the info you were looking at, we can try to understand what you meant and whether the resource/link was referring to Custom SQL or a Calculated Field.

                 

                I'm not a Custom SQL guru, so I don't fully understand the issue you're trying to explain, but if concatenating the fields after pulling the data into Tableau solves your issue, then go for it.

                 

                I, too, do not understand the observation you are making about added quotation marks. Its not clear for me, based on the screenshot and info provided thus far, but again, I'm not a Custom SQL expert.

                 

                Hope this helps.