Solved

Concatenate in SQL Server without adding

Posted on 2013-06-24
5
490 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now