Solved

Concatenate in SQL Server without adding

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
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…

737 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