Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a character into a specified position into string in SQL SERVER?

Tags:

I have a varchar field like:

195500
122222200

I need to change these values to:

1955.00
1222222.00
like image 458
Joao Paulo Avatar asked Nov 21 '13 12:11

Joao Paulo


People also ask

How can I add a character into a specific position into string in SQL Server?

In SQL Server, you can use the T-SQL STUFF() function to insert a string into another string. This enables you to do things like insert a word at a specific position. It also allows you to replace a word at a specific position. character_expression is the original string.

How do I change a character's position in SQL?

SQL Server REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.

Which function gives character position in a specified string?

We use the SQL CHARINDEX function to find the position of a substring or expression in a given string. We might have a character in different positions of a string. SQL CHARINDEX returns the first position and ignores the rest of matching character positions in a string.


1 Answers

try this

Declare @s varchar(50) = '1234567812333445'
Select Stuff(@s, Len(@s)-1, 0, '.')
--> 12345678123334.45

fiddle demo

like image 103
vhadalgi Avatar answered Sep 23 '22 13:09

vhadalgi