0

Please Excuse me if this is Simple... I am new to SQL..I am need to Run this Custom SQL Query to get data from Microsoft SQL Server. Here is this field

TitleName

abc_34235
abcd_2_56543
xyz_4532

I want to get a Column with Only these Values

34235
56543
4532

Please Help DR

PM 77-1
  • 11,712
  • 18
  • 56
  • 99
drrai66
  • 3
  • 1
  • what is your table name and what is this 34235 56543 4532 ? – Ali Eshghi Oct 08 '18 at 22:46
  • Use [STRING_SPLIT](https://docs.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql?view=sql-server-2017) function. – Alexander Petrov Oct 08 '18 at 22:50
  • Lets us Say TableName is Mytable...Basically, I want to get the numbers from last part of the String. In above example, I shouldf be getting 34235 from abc_34235 and only 56543 from abcd_2_56543. I hope it makes Sense.. Thanks – drrai66 Oct 08 '18 at 22:53
  • 1
    See https://stackoverflow.com/a/39002164/2055998 – PM 77-1 Oct 08 '18 at 22:57
  • @drrai66 does my code work? – Ali Eshghi Oct 08 '18 at 23:10
  • One More Thing...I got the values as String..How Can I get Them as Integar? – drrai66 Oct 08 '18 at 23:16
  • Yes Ali, Your Code also Worked...I marked it Correct, ONe more Question I asked how can I get those values as Integar. It is currently returning values as String. I want them as Integar .. – drrai66 Oct 08 '18 at 23:18

1 Answers1

1

I think this can help you:

select RIGHT(TitleName,LEN(TitleName)-CHARINDEX('_',TitleName)) from Mytable
Ali Eshghi
  • 670
  • 7
  • 21