CONCAT() in MySQL
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
|
show 3 more comments
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
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
tryCONCAT(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 3 more comments
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
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
mysql concat
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
tryCONCAT(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 3 more comments
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
tryCONCAT(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
|
show 3 more comments
3 Answers
3
active
oldest
votes
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;
It's not working.
– Anju Mathew
Dec 22 '15 at 11:45
@AnjuMathew:- Are you getting any error? Also what is the datatype fortransactioninfo.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 astransactioninfo
– 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
|
show 7 more comments
Please check the following. It will be worth it for you:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
add a comment |
You can use this query
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
It's not working.
– Anju Mathew
Dec 22 '15 at 11:45
@AnjuMathew:- Are you getting any error? Also what is the datatype fortransactioninfo.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 astransactioninfo
– 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
|
show 7 more comments
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;
It's not working.
– Anju Mathew
Dec 22 '15 at 11:45
@AnjuMathew:- Are you getting any error? Also what is the datatype fortransactioninfo.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 astransactioninfo
– 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
|
show 7 more comments
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;
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;
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 fortransactioninfo.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 astransactioninfo
– 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
|
show 7 more comments
It's not working.
– Anju Mathew
Dec 22 '15 at 11:45
@AnjuMathew:- Are you getting any error? Also what is the datatype fortransactioninfo.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 astransactioninfo
– 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
|
show 7 more comments
Please check the following. It will be worth it for you:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
add a comment |
Please check the following. It will be worth it for you:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
add a comment |
Please check the following. It will be worth it for you:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
Please check the following. It will be worth it for you:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
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
add a comment |
add a comment |
You can use this query
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
add a comment |
You can use this query
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
add a comment |
You can use this query
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
You can use this query
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
answered Dec 22 '15 at 11:46
Vipin JainVipin Jain
3,8301435
3,8301435
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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