Click here to Skip to main content
15,898,571 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi. I would like to ask some help in SQL.

Supposed, I have a data like this:

SQL
Num Name
1   6913413 - ABCD
2   5453 - CDE
3   12343412341324 - THEWQ


I want only to get the values before "-" in Name field.
Like this:

SQL
Num Name
1   6913413
2   5453
3   12343412341324


How would I do that?
Please help.
Thank you.
Posted

1 solution

Already solved my problem.
Below is my answer:
SQL
SELECT SUBSTRING(Name, 1, CHARINDEX( '-', Name) - 1)
 
Share this answer
 
Comments
Anoop Kr Sharma 28-Jul-13 23:25pm    
You can also check this link:-
http://stackoverflow.com/questions/375133/how-do-i-extract-part-of-a-string-in-t-sql
berrymaria 28-Jul-13 23:45pm    
thank you :)
Anoop Kr Sharma 28-Jul-13 23:56pm    
Welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900