get a substring in SQL SERVER using space as separator

get a substring in SQL SERVER using space as separator


SELECT CASE CHARINDEX(' ', news.description, 40)
  WHEN 0 THEN news.description
  ELSE SUBSTRING(news.description, 0, CHARINDEX(' ', news.description, 40) - 0)
  END
 AS FirstWord
FROM news

source:
http://www.dreamincode.net/forums/topic/239440-how-can-i-get-a-substring-in-sql-server-using-space-as-separator/
CHARINDEX (Transact-SQL) http://msdn.microsoft.com/pt-pt/library/ms186323.aspx

SUBSTRING (Transact-SQL)http://msdn.microsoft.com/en-us/library/ms187748.aspx

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *