I have table with data 1/1
to 1/20
in one column. I want the value 1 to 20 i.e value after '/'(front slash) is updated into other column in same table in SQL Server.
Example:
Column has value 1/1,1/2,1/3...1/20
new Column value 1,2,3,..20
That is, I want to update this new column.
The SUBSTRING() extracts a substring with a specified length starting from a location in an input string. In this syntax: input_string can be a character, binary, text, ntext, or image expression. start is an integer that specifies the location where the returned substring starts.
The STRING_SPLIT(string, separator) function in SQL Server splits the string in the first argument by the separator in the second argument. To split a sentence into words, specify the sentence as the first argument of the STRING_SPLIT() function and ' ' as the second argument. FROM STRING_SPLIT( 'An example sentence.
First, to split a string with SQL Server just after a certain character, use the three following built-in text functions: SUBSTRING () to trim a text by indicating the start and length to be trimmed.
In Sql 2017 and above, it’s as simple as using the STRING_SPLIT function: STRING_SPLIT ( [col], 'character to split with') AS [column name] CROSS APPLY STRING_SPLIT ( [col], 'character to split with') AS [values] The two examples there will do it.
sentence. The STRING_SPLIT (string, separator) function in SQL Server splits the string in the first argument by the separator in the second argument. To split a sentence into words, specify the sentence as the first argument of the STRING_SPLIT () function and ' ' as the second argument.
Moreover, the “STRING SPLIT” table_valued function returns an empty table if the input string is NULL. Each database is connected with a compatibility level. It enables the database’s behavior to be compatible with the particular SQL Server version it runs on. Now we will call “string_split” function to split string delimited by commas.
Try this:
UPDATE YourTable SET Col2 = RIGHT(Col1,LEN(Col1)-CHARINDEX('/',Col1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With