SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to add extra data w/o overwriting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

liliace
Starting Member

1 Posts

Posted - 10/04/2012 :  06:13:22  Show Profile  Reply with Quote
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

Edited by - liliace on 10/04/2012 06:13:46

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/04/2012 :  06:44:49  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000