SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Concatenation


Concatenation

Author
Message
koolme_85
koolme_85
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 204
i have a column abc_col1 in table A
when i do a ("Select abc_col1 from A")
i get the results as
'SHT234'
'SHT56'
'SHT7980'

i need to get the above result as
't234'
't56'
't7980'

Please advice
thanks
koolme_85
koolme_85
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 204
Never mind i just got it worked
TheSQLGuru
TheSQLGuru
SSC Guru
SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)

Group: General Forum Members
Points: 76645 Visits: 8872
Glad I could help!! :-)

Perhaps you could post your solution? One reason is so others can search for your issue and find a solution. The other is that your solution could be made even better. No downside, other than a few minutes of your time.

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Alan Burstein
Alan Burstein
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32347 Visits: 8574
A couple techniques:


SELECT RIGHT(abc_col1,len(abc_col1)-2)
FROM tableA

SELECT REPLACE(abc_col1,'SH','')
FROM tableA



-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

iamsql1
iamsql1
SSC-Addicted
SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)

Group: General Forum Members
Points: 447 Visits: 139
Use length and then substring funtionc
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)

Group: General Forum Members
Points: 506130 Visits: 44262
iamsql1 (7/26/2013)
Use length and then substring funtionc


It's easy to get to the moon. All you need to do is build a rocket ship. ;-)

How would YOU use what you suggested to accomplish the task? Some code would be a big help.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
iamsql1
iamsql1
SSC-Addicted
SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)SSC-Addicted (447 reputation)

Group: General Forum Members
Points: 447 Visits: 139
Jeff Moden (7/27/2013)
iamsql1 (7/26/2013)
Use length and then substring funtionc


It's easy to get to the moon. All you need to do is build a rocket ship. ;-)

How would YOU use what you suggested to accomplish the task? Some code would be a big help.



SUBSTRING(column, 3, len(column));

Use Column name in first and last place of argument.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)

Group: General Forum Members
Points: 506130 Visits: 44262
iamsql1 (7/27/2013)
Jeff Moden (7/27/2013)
iamsql1 (7/26/2013)
Use length and then substring funtionc


It's easy to get to the moon. All you need to do is build a rocket ship. ;-)

How would YOU use what you suggested to accomplish the task? Some code would be a big help.



SUBSTRING(column, 3, len(column));

Use Column name in first and last place of argument.


That'll work. Thanks for posting it.

As a bit of a sidebar, you can avoid the extra calculation of LEN depending on what you intend to do with the result.

SUBSTRING(column,3,8000)

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)SSC Guru (506K reputation)

Group: General Forum Members
Points: 506130 Visits: 44262
koolme_85 (7/23/2013)
Never mind i just got it worked


Very cool. What did you do to fix it?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search