Concatenate five fields where some may be NULL












0















I have a trench containing five types of ducts.
I have created fields the trenches: Type1, Type2, Type3, ...



The values in each field are the numbers of each type of duct that the trench contains.



eg. lets say that one trench contains 2 ducts of type one and one duct of type 2, then I would like to label it something like this: 2xType1,Type2



The other types are NULL. How can I write a compact expression to handle this?










share|improve this question




















  • 3





    What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

    – BERA
    Feb 28 at 10:27


















0















I have a trench containing five types of ducts.
I have created fields the trenches: Type1, Type2, Type3, ...



The values in each field are the numbers of each type of duct that the trench contains.



eg. lets say that one trench contains 2 ducts of type one and one duct of type 2, then I would like to label it something like this: 2xType1,Type2



The other types are NULL. How can I write a compact expression to handle this?










share|improve this question




















  • 3





    What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

    – BERA
    Feb 28 at 10:27
















0












0








0








I have a trench containing five types of ducts.
I have created fields the trenches: Type1, Type2, Type3, ...



The values in each field are the numbers of each type of duct that the trench contains.



eg. lets say that one trench contains 2 ducts of type one and one duct of type 2, then I would like to label it something like this: 2xType1,Type2



The other types are NULL. How can I write a compact expression to handle this?










share|improve this question
















I have a trench containing five types of ducts.
I have created fields the trenches: Type1, Type2, Type3, ...



The values in each field are the numbers of each type of duct that the trench contains.



eg. lets say that one trench contains 2 ducts of type one and one duct of type 2, then I would like to label it something like this: 2xType1,Type2



The other types are NULL. How can I write a compact expression to handle this?







qgis null concatenation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 28 at 19:55









underdark

69.1k13178346




69.1k13178346










asked Feb 28 at 10:17









SundrawSundraw

41




41








  • 3





    What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

    – BERA
    Feb 28 at 10:27
















  • 3





    What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

    – BERA
    Feb 28 at 10:27










3




3





What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

– BERA
Feb 28 at 10:27







What have you tried? You should be able to use the coalesce function in a label expression to hande nulls

– BERA
Feb 28 at 10:27












1 Answer
1






active

oldest

votes


















3














Maybe use something like the following:



replace(
if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2',
if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2',
if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')


Example






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313873%2fconcatenate-five-fields-where-some-may-be-null%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Maybe use something like the following:



    replace(
    if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2',
    if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2',
    if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')


    Example






    share|improve this answer






























      3














      Maybe use something like the following:



      replace(
      if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2',
      if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2',
      if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')


      Example






      share|improve this answer




























        3












        3








        3







        Maybe use something like the following:



        replace(
        if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2',
        if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2',
        if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')


        Example






        share|improve this answer















        Maybe use something like the following:



        replace(
        if("Type 1" > 0 and "Type 2" > 0, "Type 1" || 'x Type1, ' || "Type 2" || 'x Type2',
        if("Type 1" = 0 or "Type 1" IS NULL, "Type 2" || 'x Type2',
        if("Type 2" = 0 or "Type 2" IS NULL, "Type 1" || 'x Type1', ''))), '1x', '')


        Example







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 28 at 15:54

























        answered Feb 28 at 11:00









        JosephJoseph

        58.5k7101206




        58.5k7101206






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313873%2fconcatenate-five-fields-where-some-may-be-null%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Probability when a professor distributes a quiz and homework assignment to a class of n students.

            Aardman Animations

            Are they similar matrix