How to return a special character in a query

2

Good morning!

It may be simple to doubt, but I'm starting in SQL Server yet, so I'd like to know how to return a select a special character.

As you can see, there is the presence of a single quote in the Nat_Rec field and I can not put it in a like I think, I already tried in several ways, but I could not filter the records with the quotation mark only. If you can help me with this problem, thank you in advance!

    
asked by anonymous 11.09.2018 / 13:46

2 answers

5

The character to which it refers is not called a "single quote" but rather an apex, although in everyday life we confuse it with apostrophe . In graphical terms there is a subtle difference between apex and apostrophe.

In the ASCII table the apex has the decimal value of 39. There are a few ways to select it, one of which is through the function char () :

-- código #1
SELECT colunas
  from PC_TabM410
  where Nat_Rec = char(39);
    
11.09.2018 / 14:06
0

select * from PC_Tab410 where MesAno='08/2018' AND Nas_Rec='*'

Where * is the character you want. I would advise copying the same database character for this querry because of the formatting

    
11.09.2018 / 13:57