Solved

Replace function in sql server?

Posted on 2006-11-21
2
237 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
[X]
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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

752 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