0

I have a database column that is nvarchar(50). There are some records that might have an em dash in them. I want to find those records.

However, when I copy and paste an em-dash from another program, SQL Server Management Studio treats it like a regular hyphen.

This just returns all the parts with hyphens even though it's an em-dash in between the percent signs:

    select * from part 
    where partnum like '%−%'

How can I make SSMS search for the em-dash and not hyphens?

emdash: −

hyphen: -

In case anyone is wondering this was solved by learning how to use NVARCHAR searches. You can search for something you copy paste from another program by prefixing the search string with an 'N' like this:

SELECT * FROM part
WHERE PartNum LIKE N'%−%'
S.Mason
  • 3,397
  • 2
  • 20
  • 33
  • 2
    `when I copy and paste an em-dash from another program, SQL Server Management Studio treats it like a regular hyphen` - because you don't [put the `N`](https://stackoverflow.com/q/10025032/11683) in front of your `'%−%'`? – GSerg Jul 06 '20 at 17:27
  • In your post, you don't have an em-dash (codepoint 8212) but a "minus sign" (codepoint 8722). Neither is the plain "hyphen-minus" (cp 45) – Hans Kesting Jul 06 '20 at 17:47
  • @GSerg that's worked. That is new information for me thank you. You can make that into an answer and I can mark it correct. – S.Mason Jul 06 '20 at 20:19
  • @HansKesting I tried searching for NCHAR(8722) and I found the records I was looking for. Do you where can I find a list of all the code points? – S.Mason Jul 06 '20 at 20:20
  • 1
    @GSerg I think it does, but I had no idea that was even possible in the SQL language, first time I saw it was when you linked it above. – S.Mason Jul 06 '20 at 20:21

1 Answers1

1

You could try something like this.

select * from part 
    where partnum like '%' + NCHAR(8212) + '%'
SoundWaves
  • 125
  • 10
  • That didn't seem to find anything, but I'd like to try other codes. Where did you find the 8212? I can't seem to find a list of codes that go into NCHAR – S.Mason Jul 06 '20 at 17:22
  • I Googled the the em-dash and came up with old post. [link](https://stackoverflow.com/questions/2785805/hyphen-vs-dash-replace-dash-with-hyphen) – SoundWaves Jul 06 '20 at 17:28