CONCAT() in MySQL












0















I need an output like 500000 (Cr), and I tried this:



SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;


But I'm getting only 500000.



Table structure:



Id CreditAmount DebitAmount Transactiondate
-- ------------ ----------- ---------------
1 100000 0 2015-12-08
2 100000 5000 2015-12-08
3 100000 2000 2015-12-08
4 100000 3000 2015-12-08
5 100000 5000 2015-12-08









share|improve this question

























  • show table structure

    – Pathik Vejani
    Dec 22 '15 at 11:30











  • and sample data

    – Shadow
    Dec 22 '15 at 11:33











  • Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

    – Anju Mathew
    Dec 22 '15 at 11:36











  • try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

    – Sergio Ivanuzzo
    Dec 22 '15 at 11:40











  • Hello transactioninfo.CreditAmount or transaction.creditdAmount??

    – Jyoti Sharma
    Dec 22 '15 at 11:46
















0















I need an output like 500000 (Cr), and I tried this:



SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;


But I'm getting only 500000.



Table structure:



Id CreditAmount DebitAmount Transactiondate
-- ------------ ----------- ---------------
1 100000 0 2015-12-08
2 100000 5000 2015-12-08
3 100000 2000 2015-12-08
4 100000 3000 2015-12-08
5 100000 5000 2015-12-08









share|improve this question

























  • show table structure

    – Pathik Vejani
    Dec 22 '15 at 11:30











  • and sample data

    – Shadow
    Dec 22 '15 at 11:33











  • Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

    – Anju Mathew
    Dec 22 '15 at 11:36











  • try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

    – Sergio Ivanuzzo
    Dec 22 '15 at 11:40











  • Hello transactioninfo.CreditAmount or transaction.creditdAmount??

    – Jyoti Sharma
    Dec 22 '15 at 11:46














0












0








0








I need an output like 500000 (Cr), and I tried this:



SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;


But I'm getting only 500000.



Table structure:



Id CreditAmount DebitAmount Transactiondate
-- ------------ ----------- ---------------
1 100000 0 2015-12-08
2 100000 5000 2015-12-08
3 100000 2000 2015-12-08
4 100000 3000 2015-12-08
5 100000 5000 2015-12-08









share|improve this question
















I need an output like 500000 (Cr), and I tried this:



SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;


But I'm getting only 500000.



Table structure:



Id CreditAmount DebitAmount Transactiondate
-- ------------ ----------- ---------------
1 100000 0 2015-12-08
2 100000 5000 2015-12-08
3 100000 2000 2015-12-08
4 100000 3000 2015-12-08
5 100000 5000 2015-12-08






mysql concat






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 16:39









Peter Mortensen

13.6k1984111




13.6k1984111










asked Dec 22 '15 at 11:27









Anju MathewAnju Mathew

86




86













  • show table structure

    – Pathik Vejani
    Dec 22 '15 at 11:30











  • and sample data

    – Shadow
    Dec 22 '15 at 11:33











  • Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

    – Anju Mathew
    Dec 22 '15 at 11:36











  • try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

    – Sergio Ivanuzzo
    Dec 22 '15 at 11:40











  • Hello transactioninfo.CreditAmount or transaction.creditdAmount??

    – Jyoti Sharma
    Dec 22 '15 at 11:46



















  • show table structure

    – Pathik Vejani
    Dec 22 '15 at 11:30











  • and sample data

    – Shadow
    Dec 22 '15 at 11:33











  • Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

    – Anju Mathew
    Dec 22 '15 at 11:36











  • try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

    – Sergio Ivanuzzo
    Dec 22 '15 at 11:40











  • Hello transactioninfo.CreditAmount or transaction.creditdAmount??

    – Jyoti Sharma
    Dec 22 '15 at 11:46

















show table structure

– Pathik Vejani
Dec 22 '15 at 11:30





show table structure

– Pathik Vejani
Dec 22 '15 at 11:30













and sample data

– Shadow
Dec 22 '15 at 11:33





and sample data

– Shadow
Dec 22 '15 at 11:33













Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

– Anju Mathew
Dec 22 '15 at 11:36





Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

– Anju Mathew
Dec 22 '15 at 11:36













try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

– Sergio Ivanuzzo
Dec 22 '15 at 11:40





try CONCAT(CONVERT(SUM(transactioninfo.CreditAmount),char),'Cr')

– Sergio Ivanuzzo
Dec 22 '15 at 11:40













Hello transactioninfo.CreditAmount or transaction.creditdAmount??

– Jyoti Sharma
Dec 22 '15 at 11:46





Hello transactioninfo.CreditAmount or transaction.creditdAmount??

– Jyoti Sharma
Dec 22 '15 at 11:46












3 Answers
3






active

oldest

votes


















1














You can try to CAST your value as varchar and then try like this:



SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;





share|improve this answer


























  • It's not working.

    – Anju Mathew
    Dec 22 '15 at 11:45











  • @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

    – Rahul Tripathi
    Dec 22 '15 at 11:46













  • Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

    – Anju Mathew
    Dec 22 '15 at 11:49













  • @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

    – Rahul Tripathi
    Dec 22 '15 at 11:50













  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

    – Anju Mathew
    Dec 22 '15 at 11:52



















2














Please check the following. It will be worth it for you:



SELECT 
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo





share|improve this answer

































    0














    You can use this query



     SELECT concat(creditdAmount,' (Cr)') FROM  
    (
    SELECT SUM(id) AS creditdAmount FROM transaction
    )as temp;





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2fstackoverflow.com%2fquestions%2f34414880%2fconcat-in-mysql%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can try to CAST your value as varchar and then try like this:



      SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;





      share|improve this answer


























      • It's not working.

        – Anju Mathew
        Dec 22 '15 at 11:45











      • @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

        – Rahul Tripathi
        Dec 22 '15 at 11:46













      • Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

        – Anju Mathew
        Dec 22 '15 at 11:49













      • @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

        – Rahul Tripathi
        Dec 22 '15 at 11:50













      • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

        – Anju Mathew
        Dec 22 '15 at 11:52
















      1














      You can try to CAST your value as varchar and then try like this:



      SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;





      share|improve this answer


























      • It's not working.

        – Anju Mathew
        Dec 22 '15 at 11:45











      • @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

        – Rahul Tripathi
        Dec 22 '15 at 11:46













      • Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

        – Anju Mathew
        Dec 22 '15 at 11:49













      • @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

        – Rahul Tripathi
        Dec 22 '15 at 11:50













      • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

        – Anju Mathew
        Dec 22 '15 at 11:52














      1












      1








      1







      You can try to CAST your value as varchar and then try like this:



      SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;





      share|improve this answer















      You can try to CAST your value as varchar and then try like this:



      SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 22 '15 at 11:53

























      answered Dec 22 '15 at 11:40









      Rahul TripathiRahul Tripathi

      127k21163238




      127k21163238













      • It's not working.

        – Anju Mathew
        Dec 22 '15 at 11:45











      • @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

        – Rahul Tripathi
        Dec 22 '15 at 11:46













      • Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

        – Anju Mathew
        Dec 22 '15 at 11:49













      • @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

        – Rahul Tripathi
        Dec 22 '15 at 11:50













      • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

        – Anju Mathew
        Dec 22 '15 at 11:52



















      • It's not working.

        – Anju Mathew
        Dec 22 '15 at 11:45











      • @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

        – Rahul Tripathi
        Dec 22 '15 at 11:46













      • Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

        – Anju Mathew
        Dec 22 '15 at 11:49













      • @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

        – Rahul Tripathi
        Dec 22 '15 at 11:50













      • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

        – Anju Mathew
        Dec 22 '15 at 11:52

















      It's not working.

      – Anju Mathew
      Dec 22 '15 at 11:45





      It's not working.

      – Anju Mathew
      Dec 22 '15 at 11:45













      @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

      – Rahul Tripathi
      Dec 22 '15 at 11:46







      @AnjuMathew:- Are you getting any error? Also what is the datatype for transactioninfo.CreditAmount column? Also you have linked two table in your query 1. transactioninfo 2. transaction.

      – Rahul Tripathi
      Dec 22 '15 at 11:46















      Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

      – Anju Mathew
      Dec 22 '15 at 11:49







      Yes. I'm getting syntax error. Sorry, it's actually transactioninfo and the datatype is double

      – Anju Mathew
      Dec 22 '15 at 11:49















      @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

      – Rahul Tripathi
      Dec 22 '15 at 11:50







      @AnjuMathew:- Whats the error? Also I have updated the query, assuming the table name as transactioninfo

      – Rahul Tripathi
      Dec 22 '15 at 11:50















      You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

      – Anju Mathew
      Dec 22 '15 at 11:52





      You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50)),' (Cr)') AS AmountCredited -- (SUM(transactioninfo.CreditA' at line 11

      – Anju Mathew
      Dec 22 '15 at 11:52













      2














      Please check the following. It will be worth it for you:



      SELECT 
      CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
      FROM transactioninfo





      share|improve this answer






























        2














        Please check the following. It will be worth it for you:



        SELECT 
        CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
        FROM transactioninfo





        share|improve this answer




























          2












          2








          2







          Please check the following. It will be worth it for you:



          SELECT 
          CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
          FROM transactioninfo





          share|improve this answer















          Please check the following. It will be worth it for you:



          SELECT 
          CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
          FROM transactioninfo






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 16:39









          Peter Mortensen

          13.6k1984111




          13.6k1984111










          answered Dec 22 '15 at 11:55









          Jyoti SharmaJyoti Sharma

          941512




          941512























              0














              You can use this query



               SELECT concat(creditdAmount,' (Cr)') FROM  
              (
              SELECT SUM(id) AS creditdAmount FROM transaction
              )as temp;





              share|improve this answer




























                0














                You can use this query



                 SELECT concat(creditdAmount,' (Cr)') FROM  
                (
                SELECT SUM(id) AS creditdAmount FROM transaction
                )as temp;





                share|improve this answer


























                  0












                  0








                  0







                  You can use this query



                   SELECT concat(creditdAmount,' (Cr)') FROM  
                  (
                  SELECT SUM(id) AS creditdAmount FROM transaction
                  )as temp;





                  share|improve this answer













                  You can use this query



                   SELECT concat(creditdAmount,' (Cr)') FROM  
                  (
                  SELECT SUM(id) AS creditdAmount FROM transaction
                  )as temp;






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 22 '15 at 11:46









                  Vipin JainVipin Jain

                  3,8301435




                  3,8301435






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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%2fstackoverflow.com%2fquestions%2f34414880%2fconcat-in-mysql%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

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks