string - SQL Statement to return before a certain character -


i need able output string return everthing specified character, believe making use of charindex best way approach unsure of syntax required.

some examples:

  • if string equal "601-test-test2_test3" wish return 601
  • if string equal "42-test_test3" wish return 42
  • if string equal "1-test_test3" wish return 1

-- should require:  declare @string nvarchar(50)  set @string = '601-test-test2_test3'  select @string 'test string', left(@string, charindex('-', @string) - 1) 'upto-' 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -