Solved

Concatenate in SQL Server without adding

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQl Query to find x consecutive Nbrs in a Table 30 98
Syntax Issue with SSIS module 26 105
Parse this column 6 27
Current Month Filter in Visual Studio 10 24
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…

821 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