[Transact-SQL] to find out that does not contain letters, Chinese characters do not contain data

Original: [] to find the Transact-SQL does not contain letters, Chinese characters do not contain data

 

Testing colleagues, let me help write sql statement to identify table columns xx line does not contain Chinese characters.

 

The following code will be realized.

 


   
   
  1. IF EXISTS( SELECT * FROM sys.tables WHERE name = 't')
  2. DROP TABLE t
  3. go
  4. CREATE TABLE t( str VARCHAR( 100))
  5. INSERT INTO t
  6. VALUES( 'abc'),( 'ABZ'),( 'abc一二三'),( '一二三'),( '123456789')
  7. --1.不包含字母
  8. SELECT *
  9. FROM t
  10. WHERE str NOT LIKE '%[a-zA-Z]%'
  11. SELECT *
  12. FROM t
  13. WHERE patindex( '%[a-zA-Z]%', str) = 0
  14. --2.不包含汉字
  15. SELECT *
  16. FROM t
  17. WHERE str NOT LIKE '%[吖-座]%'
  18. SELECT *
  19. FROM t
  20. WHERE patindex( '%[吖-座]%', str) = 0

 

Published 416 original articles · won praise 135 · views 940 000 +

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12019955.html