Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using substring to stop at line break

Author  Topic 

cstokes91
Yak Posting Veteran

72 Posts

Posted - 2013-01-29 : 09:45:00
Hey,

This may be simple but I have been searching for this for a couple of hours now and haven't really been able to find anything on this.

I need a code that will take a string and stop when there is a line break for the length.

I've thought of substring(columnName, 0, (char(13)+char(10))) but it data type char is invalid for argument 3 of substring function.

Then I tried SUBSTRING(AlertInfo,0,CHARINDEX((CHAR(13)+CHAR(10)),AlertInfo,0))

This syntax wise ran good but returned empty values.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-29 : 09:52:12

SELECT STUFF(columnname,CHARINDEX(CHAR(10) + CHAR(13),columnname),LEN(columnname),'') FROM table

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-01-29 : 14:41:35
I think a line break can be either CHAR(10) by itself or CHAR(13) + CHAR(10). So:

LEFT(AlertInfo, CHARINDEX(CHAR(10), REPLACE(AlertInfo, CHAR(13), '') + CHAR(10))
Go to Top of Page
   

- Advertisement -