Replace every comma in a column with a dot - sql

Could someone tell me a query to replace every comma from a column 'myColumn' with a dot, without messing up with the numbers?

You would use an update statement:
update t
set myColumn = replace(myColumn, ',', '.')
where myColumn like '%,%'

Pruebe con:
UPDATE prices SET pvp = REPLACE(pvp, ',', '.');

Related

Replacing all doubles quotes from SQL table

Im trying to remove all instances of double quotes from an entire SQL table, and replace these double quotes " " with signle quotes ' '.
Is there an efficient way to do this? thanks!
If you want to change the column names, you would need to update the table:
update tablename
select column_name = replace(column_name, '"', '')
where column_name like '%"%';
To replace double quotes with single quotes, simply do
Update table
set column=replace('"','''')
where column like '%"%'
If you just want to select that column without any double quote in it:
SELECT *,REPLACE(columnname, '"','') FROM tableName
If you want to update you column by replacing all the double quote(") then Gordon provided you the right answer.
update tablename select columnname = replace(columnname, '"', '') WHERE charindex('"',columnname)>0

How to remove newline from column values in Sybase

i have a table in sybase that has 7 columns.
The sixth column has a new line as the last character in all the values. This newline is messing up the output when i export the table. How can i remove the newline character from all values in this column ?
this did the trick
update tableName
set column_name =str_replace(column_name, char(13), null)
Depending on whether the newline is in windows or unix format, one of the below should work:
UPDATE tableName SET column_name = str_replace(column_name, char(13), null)
or
UPDATE tableName SET column_name = str_replace(column_name, CHAR(13) + CHAR(10), '')

Remove extra space from column values

I have a column in Oracle database, where I had stored concatenated values. For example,
/uk/letters/default?/uk/letters/funny_letters?
/uk/letters/letters?/library/conditionalstyle?o=3&f=11/uk/letters/funny_letters?
/uk/workinglife/viewarticle_93?/library/conditionalstyle?/uk/financialcentre/car_tax_calculator?
/uk/job-hunting/default?/partners/msn/i-resignfinctr?/uk/letters/letters?/
In between the urls, there are some spaces in between. How can I remove them?
UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, ' ', '')
This is too late but will help some one.
select regexp_replace(column_name, '[[:space:]]+', chr(32)) from table_name;
After verification , you can update the table as follows;
UPDATE table_name
SET column_name = REGEXP_REPLACE (column_name ,'[[:space:]]+',' ');

Remove single characters in sql records?

I'm working on importing some files and I noticed that some of the email addresses are prefixed with a comma.
Eg: ,abc#abc.com
In a table with 1500 emails, I've found that 700+ of these have this issue.
How would I update them so that the comma is removed?
UPDATE dbo.Table
SET Email = STUFF(Email, 1, 1, '')
WHERE Email LIKE ',%';
try:
UPDATE YourTable
SET YourColumn=RIGHT(YourColumn,LEN(YourColumn)-1)
WHERE LEFT(YourColumn,1)=','
If you know they always start with a ,:
UPDATE SomeTable
SET SomeColumn = SUBSTRING(SomeColumn, 2, 4000)
WHERE SomeColumn LIKE ',%';
Otherwise you could do this to get rid of all , no matter where they appear. Note that here adding a WHERE SomeColumn LIKE '%,%' clause might adversely affect performance.
UPDATE SomeTable
SET SomeColumn = REPLACE(SomeColumn, ',', '');
UPDATE table SET email = SUBSTRING(email, 2, 1000) WHERE email LIKE ",%";
The % is a wildcard, so this will only match those fields that start with a comma.

LTRIM usage with SQL server 2005

I am a bit of an sql noob so please forgive. I can't seem to find a usage example of LTRIM anywhere.
I have a NVARCHAR column in my table in which a number of entries have leading whitespace - I'm presuming if I run this it should do the trick:
SELECT LTRIM( ColumnName)
From TableName;
Will this give the desired result?
No, it will trim leading spaces but not all white space (e.g. carriage returns).
Edit
It seems you are looking for an UPDATE query that will remove leading and trailing whitespace.
If by that you only mean "normal" spaces just use
UPDATE TableName
SET ColumnName = LTRIM(RTRIM(ColumnName ))
For all white space this should do it (from the comments here). Backup your data first!
UPDATE TableName
SET ColumnName =
SUBSTRING(
ColumnName,
PATINDEX('%[^ ' + char(09) + char(10) + char(13) + char(20) + ']%',
ColumnName),
LEN(ColumnName) - PATINDEX('%[^ ' + char(09) + char(10) + char(13) + char(20) + ']%'
, ColumnName) -
PATINDEX('%[^ ' + char(09) + char(10) + char(13) + char(20) + ']%',
REVERSE(ColumnName)) + 2)
Your example will work to remove the leading spaces. This will only select it from the database. IF you need to actually change the data in your table, you will need to write an UPDATE statement something like:
UPDATE TableName
SET ColumnName = LTRIM(ColumnName)
If you need to remove spaces from the right side, you can use RTRIM.
Here is a list of the string functions in SQL Server 2005 that I always refer to:
http://msdn.microsoft.com/en-us/library/ms181984(v=SQL.90).aspx
Did you run it to find out? It's just a select, it won't blow up your database. But, yes.
Select LTRIM(myColumn) myColumn
From myTable
Should return the myColumn values with any leading whitespace removed. Note this is only leading whitespace.
EDIT To Update the column, with the above, you'd do:
Update myTable
Set myColumn = LTRIM(myColumn)
From myTable