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 return601
- if string equal
"42-test_test3"
wish return42
- if string equal
"1-test_test3"
wish return1
-- should require: declare @string nvarchar(50) set @string = '601-test-test2_test3' select @string 'test string', left(@string, charindex('-', @string) - 1) 'upto-'
Comments
Post a Comment