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 2005 Forums
 Transact-SQL (2005)
 Convert Hyphen to Dash

Author  Topic 

caravanpunk
Starting Member

20 Posts

Posted - 2012-07-16 : 12:43:26
Hello Need to update a field in a table

The Update is to change Hyphen with a Dash.

(table_A)-- Column is Group_Name (Varchar(100)

Group_Name has a record called 'SuperHero-Test1'
with 'SuperHero—Test1'.

When Copying and Pasting 'SuperHero—Test1' into Mgmt studio, somehow will show as SuperHero-Test1.

Is there a way to change hyphen to Dash? or is it by default that Sql Server allows only hyphens?

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-07-16 : 13:33:25
SQL Server allows both. You should be able to replace anything you like:
DECLARE @Foo VARCHAR(100) =  'SuperHero—Test1';
SELECT
REPLACE(@Foo, CHAR(151), CHAR(45)),
REPLACE(@Foo, '—', '-')
Go to Top of Page

caravanpunk
Starting Member

20 Posts

Posted - 2012-07-16 : 13:57:59
Thanks, but was trying to find a way to enter a Dash in
SuperHero-Test1.

While copying SuperHero-Test1(Dash) from word doc,into Sql Server--Sql Server automatically converts SuperHero-Test1 to Hyphen.

Is there a way i can populate SuperHero-Test1(Dash) in Sql Server By itself.

I did copied and pasted your Output (Dash) into mine, and it worked.


Thanks
Go to Top of Page

caravanpunk
Starting Member

20 Posts

Posted - 2012-07-16 : 14:19:28
Lamprey, i got the answer

Update Table1 set Group_Name=Replace('SuperHero-Test1',char(45),char(151)) where Group_Name='SuperHero-Test1'

Thanks so much--
Go to Top of Page
   

- Advertisement -