Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to add extra data w/o overwriting

Author  Topic 

liliace
Starting Member

1 Post

Posted - 2012-10-04 : 06:13:22
Hi, i need help to add some extra data into a column w/o overwriting the content that is already there.

For example i have two columns below:

Longitude
81,469488
45.090853

AND

Latitude
28,427452
1.148787

but i want to add a '-' to all longitude data:
Longitude
-81,469488
-45.090853

AND

Latitude
28,427452
1.148787

And how to remove if there are some unwanted '-' in some columns.

Thank you very much in advance!
Lili

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-04 : 06:44:49
How you would do this VERY MUCH depends on what the data type of the columns are. If they are numeric (such as float, decimal etc.), you would do the following:
UPDATE YourTable SET Longitude = -(ABS(Longitude)), Latitude = ABS(Latitude);
If it is character type of data, you would do the following:
UPDATE YourTable SET 
Longitude = '-'+REPLACE(Longitude,'-',''),
Latitude = REPLACE(Latitude,'-','');
You can look up the data types using the following query:
SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.Columns WHERE 
TABLE_NAME = 'YourTableName';
Go to Top of Page
   

- Advertisement -