Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Complex Concatenation

Author  Topic 

blamey4
Starting Member

1 Post

Posted - 2010-01-25 : 18:57:00
Any help would be great!!!

SQL Server 2008

What table currently looks like

Corp Acct Cust
15515 123456 10
15515 12345 4
15515 1234 1
15515 12 10


Corp Column should always be 5 characters
Acct Column should always be 6 charcters
Cust Column should always be 2 charcters


What I need it to look like after Concatenation

Concatenation
1551512345610
1551501234504
1551500123401
1551500001210

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2010-01-25 : 20:10:36
Try with Case... With Len Function.
Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2010-01-25 : 21:08:20
try this one;
select RIGHT('00000' + CAST(1 AS varchar(5)) ,5)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-25 : 23:53:43
[code]select right('00000'+ cast(Corp as varchar(5)),5) + right('000000'+ cast(Acct as varchar(6)),6) + right('00'+ cast(Cust as varchar(2)),2)
from table [/code]
Go to Top of Page
   

- Advertisement -