32

In SQL Server, what is the best way to identify all rows in a table where a certain column contains the TAB character (CHAR(9))

Is it as simple as

SELECT * FROM MyTable WHERE Field1 LIKE '%' + CHAR(9) + '%'

2 Answers 2

37

RTRIM CHAR columns. like this:

SELECT        *
FROM          MyTable 
WHERE        (RTRIM(Field1) LIKE '%' + CHAR(9) +  '%')
1
  • What does add RTRIM to this specific query? with or without does not seem to change much in my tests
    – camillo777
    May 10 at 9:08
-3

Previous query fails, with: "missing expression" message, In Oracle, this is the correct syntax

select *
  from MyTable
 where Field1 '%' || CHR(9) || '%';

Other solution can be:

Select *
  from MyTable
  where instr(Field1, CHR(9)) <> 0;

Cheers!

1
  • 10
    This question only has SQL Server tags. Your answer is redundant.
    – s.brody
    Jun 7, 2017 at 8:06

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.