Solved

Concatenate in SQL Server without adding

Posted on 2013-06-24
5
493 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
  • 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:ewangoya
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 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