SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using substring to stop at line break
 New Topic  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

547 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  
 New 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.03 seconds. Powered By: Snitz Forums 2000