September 22, 2015 at 12:32 pm
I have data like ABC_Tablename_12345, i just want everything before and after _ also if there is no underscore in the name just return the name. Can somone help me with this please. Thanks
September 22, 2015 at 12:38 pm
You can use CHARINDEX and SUBSTRING to achieve this.
Give it a try and post it. If you still have problems we can give you a hand.
September 22, 2015 at 12:42 pm
SELECT LEFT(column_name, CHARINDEX('_', column_name + '_') - 1) AS before_underscore,
SUBSTRING(column_name, CHARINDEX('_', column_name + '_') + 1, 2000) AS after_underscore
FROM table_name
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply