1
declare @tachareName varchar(200)
        ,@a varchar
set @tachareName='fsfhk,fsif,'
if(CHARINDEX(',',@tachareName)!=0)              
    --print @tachareName
    --select REPLACE(@tachareName,',',' ')--The output is:fsfhk fsif 
    set @a=REPLACE(@tachareName,',',' ')
    --REPLACE(@tachareName,',',' ')
    print @a    --The output is:f

What's wrong,i want to judge if the string has ',' symbal and repalce it with ' '.

The envirioment is SQL Server 2008.

1 Answer 1

2

Because of your declaration of @a - you have not declared length of variable so it defaulted to 1. Thus returning only the first letter of result.

Declare @a as:

declare @a varchar(200)

Read more about char and varchar declaration on MSDN.

Sign up to request clarification or add additional context in comments.

1 Comment

There's a suggestion to change this very thing on Microsoft Connect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.