Split the string. get first value of split SQL Server 2005


I have a table called TableReason with a column called Reason.

Reason datatype is varchar(100) and contains values like this 2,-2,22,33,0,2 for one row

I need to write an update statement for this table to accomplish: only need first value of split with comma, ie. 2 only needed.

update TableReason set reason=--please help me on this.


... set reason=CASE CHARINDEX(',', reason) WHEN 0 THEN reason WHEN 1 THEN '' ELSE LEFT(reason, CHARINDEX(',', reason)-1) END

This deals with the 3 cases of

<ul><li>no comma</li> <li>first character is a comma</li> <li>a number followed by a comma</li> </ul>


  • Python: Split a String Field into 3 Separate Fields using Lambda
  • how can I compare dates in array to find the earliest one?
  • Divide a $1 by 3 and adjusting 1 cent
  • .NET video play library which allows to change the playback rate?
  • Can my PDF ping my server when it is opened?
  • Two Tables Serving as one Model in Rails
  • How to 'create temp table as select' in Slick?
  • How do I shift the decimal place in Python?
  • Approximate Order-Preserving Huffman Code
  • How to assign byte[] as a pointer in C#
  • MySQL Order by column = x, column asc?
  • Unable to get column index with table.getColumn method using custom table Model
  • How can I extract results of aggregate queries in slick?
  • Word Open XML Mail Merge
  • Replace value with Factor in r data.table
  • Database structure design with variable amounts of fields
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How to add date and time under each post in guestbook in google app engine
  • Submit form in a displaytag pagination
  • Convert array of 8 bytes to signed long in C++
  • what is the difference between the asp.net mvc application and asp.net web application
  • Weird JavaScript statement, what does it mean?
  • Delete MySQLi record without showing the id in the URL
  • SVN: Merging two branches together
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Unanticipated behavior
  • Comma separated Values
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Trying to get generic when generic is not available
  • Understanding cpu registers
  • coudnt use logback because of log4j
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Add sale price programmatically to product variations
  • unknown Exception android
  • Can't mass-assign protected attributes when import data from csv file
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Unable to use reactive element in my shiny app