How to remove newline from column values in Sybase - sql

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), '')

Related

Not able to TRIM trailing space in varchar column in oracle

I am using oracle 11g DB and in one of the table having varchar column has data which has trailing spaces. I have tried TRIM function to update the column but still the space at the end of the string prevails. What can be the reason for the trailing space? and how to fix this issue.
Column contents are displayed as below.
select '<'||mycol||'>' from mytab
Output : <mysamplestring >
select DUMP(mycol) from mytab
Output : Typ=1 Len=28: 67,114,117,100,101,32,80,101,116,114,111,108,101,117,109,32,69,120,116,114,97,99,116,105,111,110,194,160
Thanks
Using UNISTR did the trick for me. It removed the characters 160 and 194
update mytab set mycol = REPLACE(mycol,unistr('\00A0'),'')
trim() should work as expected! Sure it is a varchar2 column not a char column?
update hr.countries t
set t.country_name = t.country_name || ' ';
update hr.countries t
set t.country_name = trim(t.country_name);
Change the column type from char to varchar2, char column blank-pads the value with spaces to fill up the size of the field. So for a char(10) column, when you insert 'abc', it will automatically be inserted as 'abc '

Replace every comma in a column with a dot

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, ',', '.');

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:]]+',' ');

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

Importing a table from Access into SQL and removing the carriage returns

I'm importing a table from Access that has an address field the address field contains carriage returns, these remain when I have imported them into SQL, can I run a SQL script to remove them? Any ideas much appreciated.
This will replace Carriage Returns (char(13)) with a single space:
UPDATE MyTable
SET MyColumn = Replace(MyColumn, CHAR(13), ' ')
If you have Carriage Return + LineFeeds:
UPDATE MyTable
SET MyColumn = Replace(MyColumn, CHAR(13)+CHAR(10), ' ')
You can use this query to replace newline with empty space:
replace ( replace(TextValue, char(10),' '), char(13), ' ')