August 17, 2015 at 3:40 am
is it possible to change any line breaks or newlines for a string
in a select statement in a store procedure, in this way I can reproduce text in a label on a webpage complete with line breaks
August 17, 2015 at 4:03 am
I've tried the following
SELECT ROW_NUMBER() OVER
(
ORDER BY [recid] desc
)AS RowNumber
,[recid]
,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >')
,[dte]
INTO #Results
text1 is a text field, the error I'm getting is :
Msg 1038, Level 15, State 5, Procedure GetCustomersPageWise, Line 9
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
August 17, 2015 at 4:55 am
With help from a colleague I've come up with the following that works.
SET NOCOUNT ON;
SET DATEFORMAT dmy;
SELECT ROW_NUMBER() OVER
(
ORDER BY [recid] desc
)AS RowNumber
,[recid]
,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >') as text1
,[dte]
INTO #Results
August 17, 2015 at 4:56 am
The answer's right there in the error message. You don't have an alias for the third column of your SELECT statement.
John
August 17, 2015 at 8:15 am
mick burden (8/17/2015)
With help from a colleague I've come up with the following that works.
SET NOCOUNT ON;
SET DATEFORMAT dmy;
SELECT ROW_NUMBER() OVER
(
ORDER BY [recid] desc
)AS RowNumber
,[recid]
,REPLACE(REPLACE(text1, CHAR(13), '<br >'), CHAR(10), '<br >') as text1
,[dte]
INTO #Results
That can very easily lead to double spacing. I've seen files with CrLf and files with just Lf. I've not see files with just Cr. So, the replace line should probably change Cr to nothing and just work with the Lf. Like this...
,REPLACE(REPLACE(text1, CHAR(13), ''), CHAR(10), '<br >') as text1
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply