sql server 2005 - Returning first line from a string -


I have a string in which there are three lines, how can I withdraw the first line from a string in i sqlserver.

Foreign currency:

  Declare as Narrator @ (200) set @ straw = 'this is for testing' + (four) + 'second line '+ Four (10) +' third line 'in some test tables   

How can I return the first line from this?

  SELECT SUBSTRING (@ Str, 0, CHARINDEX (char (10), @ str) ) Edit: If you have only text with one line, then you can use a case:  
  select CHARINDEX (Char (10), @ str) = 0 THEN @Str ELSE SUBSTRING (@ Str, 0, CHARINDEX (four (10), @ str)) END    

Comments