Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Concatenation Expand / Collapse
Author
Message
Posted Tuesday, July 23, 2013 10:44 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:22 AM
Points: 82, Visits: 192
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

Post #1476717
Posted Tuesday, July 23, 2013 10:47 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:22 AM
Points: 82, Visits: 192
Never mind i just got it worked
Post #1476718
Posted Tuesday, July 23, 2013 12:19 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:18 PM
Points: 4,406, Visits: 6,268
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 at GMail
Post #1476746
Posted Wednesday, July 24, 2013 2:54 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 9:30 PM
Points: 612, Visits: 2,857
A couple techniques:

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

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



-- Alan Burstein



Read this article for best practices on asking questions.
Need to split a string? Try this (Jeff Moden)
Need a pattern-based string spitter? Try this (Dwain Camps)

"I can't 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. " -- Itzek Ben-Gan 2001

My blog
Post #1477281
Posted Friday, July 26, 2013 3:52 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, September 16, 2013 11:20 AM
Points: 45, Visits: 139
Use length and then substring funtionc
Post #1478227
Posted Saturday, July 27, 2013 9:50 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:38 PM
Points: 35,371, Visits: 31,912
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1478290
Posted Saturday, July 27, 2013 2:35 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, September 16, 2013 11:20 AM
Points: 45, 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.
Post #1478308
Posted Saturday, July 27, 2013 3:27 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:38 PM
Points: 35,371, Visits: 31,912
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1478312
Posted Saturday, July 27, 2013 3:28 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:38 PM
Points: 35,371, Visits: 31,912
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1478313
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse