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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update query - Add a dash to everthing in field

Author  Topic 

pmp7798
Starting Member

2 Posts

Posted - 2013-11-23 : 11:09:24
I am trying to write the correct syntax for adding a dash to everything in a specific field.
The query I came up with:

update table1
set field1 = '-' & [field1]
from table1

syntax works in access but not SQL SERVER 2008. I need the SQL 2008 syntax. Please help


original data in field

field1: 1 Result I need: field1: -1

paul pearson

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-23 : 11:40:10
+ is the concatenation operator in sql server

update table1
set field1 = '-' + [field1]



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pmp7798
Starting Member

2 Posts

Posted - 2013-11-23 : 12:28:11
What if field1 is an int field? do I have to do a conversion?

paul pearson
Go to Top of Page

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-11-25 : 08:07:24
If you have an integer column try multiplying by -1.

djj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-25 : 09:27:09
quote:
Originally posted by pmp7798

What if field1 is an int field? do I have to do a conversion?

paul pearson


wats your attempt? to make it negative?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -