SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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  

cstokes91
Yak Posting Veteran

USA
59 Posts

Posted - 01/29/2013 :  09:45:00  Show Profile  Reply with Quote
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

India
52309 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
http://visakhm.blogspot.com/

Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
340 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.05 seconds. Powered By: Snitz Forums 2000