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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using substring to stop at line break
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

72 Posts

Posted - 01/29/2013 :  09:45:00  Show Profile  Reply with Quote

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.

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/29/2013 :  09:52:12  Show Profile  Reply with Quote

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

SQL Server MVP

Go to Top of Page

Aged Yak Warrior

550 Posts

Posted - 01/29/2013 :  14:41:35  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000