Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Replace function in sql server?

Posted on 2006-11-21
2
233 Views
Last Modified: 2008-01-09
Dear Experts,

I have write some code in stored procedure.
Why i cant get 4000 chars once it runs replace function.
It only return 3999 chars after it runs replace function.
May i know how to solve this problem where it return 4000 chars after the replace function end?
For your information,
The first print display 4000 chars which is correct.
But after it runs replace functions it left 3999 chars only.

Select @strXML1 = CONVERT(nvarchar(4000), SUBSTRING(XMLData,1,4000)), @strPosition1 = charindex(char(39),xmldata) from tb_batchpocreation_Queue Where QueueID = @QueueID
      
print @strXML1

      If @strPosition1 <> 0
      Begin
            Set @strXML1 =       replace(@strXML1,char(39),char(39)+ char(39))
      End

print @strXML1
0
Comment
Question by:sonny_j81
2 Comments
 
LVL 9

Expert Comment

by:csk_73
ID: 17986145
Hi sonny_j81,

just trying, but try with

replace(@strXML1,nchar(39),nchar(39)+nchar(39)

as strXML1 is an nvarchar I suppose it's better to use nchar...

Hope this helps!

Cesc
0
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 17986213
try changing datatype of @strXML1 from nvarchar(4000) to nchar(4000)
and also

Select @strXML1 = CONVERT(nvarchar(4000), SUBSTRING(XMLData,1,4000))

to

Select @strXML1 = CONVERT(nchar(4000), SUBSTRING(XMLData,1,4000))
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Row insertion failed. Array 5 47
Error when creating a table from a function 6 18
SQLCMD Syntax 2 14
use of sqlCmd command through exec master..xp_cmdshell 7 14
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question