Solved

Concatenate in SQL Server without adding

Posted on 2013-06-24
5
497 Views
Last Modified: 2013-06-24
HI I have an expression that I need to concatenate three integers. The problem is that SQL is adding the three numbers instead of concatenating them. I'm using SQL Server 2008 R2

select MIN(ID) as minimalID, NewDesc, BankAccount, BankDate, MONTH(GETDATE()), DAY(GETDATE()),(MIN(ID)+ cast((MONTH(GETDATE())) as varchar(2)) + cast((DAY(GETDATE())) as varchar(2)))
from  dbo.[BNKRecon_4_5_tblBNKRecon*GroupedPmtIDs]

group by NewDesc, BankAccount, BankDate

Open in new window


So if the three numbers are 345 +6+12 i want the answer to be 345612 rather than 363

thanks
0
Comment
Question by:damixa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:David Kroll
ID: 39272051
select MIN(ID) as minimalID, NewDesc, BankAccount, BankDate, MONTH(GETDATE()), COALESCE(DAY(GETDATE()), (MIN(ID), '') + COALESCE(cast((MONTH(GETDATE())) as varchar(2)), '') + COALESCE(cast((DAY(GETDATE())) as varchar(2))), '')
from  dbo.[BNKRecon_4_5_tblBNKRecon*GroupedPmtIDs]

group by NewDesc, BankAccount, BankDate
0
 

Author Comment

by:damixa
ID: 39272123
For some reason its not working and its not even showing the concatenation at all.
0
 
LVL 11

Accepted Solution

by:
David Kroll earned 500 total points
ID: 39272154
select MIN(ID) as minimalID, NewDesc, BankAccount, BankDate, MONTH(GETDATE()), DAY(GETDATE()),
COALESCE(CONVERT(VARCHAR, MIN(ID)), '') +
COALESCE(CONVERT(VARCHAR, MONTH(GETDATE())), '') +
COALESCE(CONVERT(VARCHAR, DAY(GETDATE())), '')
from  dbo.[BNKRecon_4_5_tblBNKRecon*GroupedPmtIDs]

group by NewDesc, BankAccount, BankDate
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 39272160
try
select MIN(ID) as minimalID, NewDesc, BankAccount, BankDate, MONTH(GETDATE()), DAY(GETDATE()),
	(CAST(MIN(ID) as varchar) + cast((MONTH(GETDATE())) as varchar(2)) + cast((DAY(GETDATE())) as varchar(2)))
from  dbo.[BNKRecon_4_5_tblBNKRecon*GroupedPmtIDs]

group by NewDesc, BankAccount, BankDate

Open in new window

0
 

Author Closing Comment

by:damixa
ID: 39272178
Thanks,
Perfect
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question