August 28, 2012 at 4:17 am
hello all.
I have one string like this:'0,0,'',0,'',0' and i want to my result this:'0,null,'',0,'',0' please guide me how to do i do for this result?
thanks
August 28, 2012 at 4:32 am
Do you always want to NULL the second zero, or is it more complicated?
August 28, 2012 at 4:33 am
yes always
August 28, 2012 at 4:35 am
elham_azizi_62 (8/28/2012)
hello all.I have one string like this:'0,0,'',0,'',0' and i want to my result this:'0,null,'',0,'',0' please guide me how to do i do for this result?
thanks
No problem.
-- set up sample data
DECLARE @String VARCHAR(50), @Replacement VARCHAR(50)
SELECT @String = '0,0,'',0,'',0', @Replacement = '0,null,'',0,'',0'
SELECT String = @String, Replacement = @Replacement
-- solution
SELECT CASE WHEN @String = @String THEN @Replacement ELSE @String END
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 28, 2012 at 4:37 am
You can do this:
SELECT REPLACE('0,0,'',0,'',0', '0,0', '0,NULL')
This will be OK as long as the pattern only occurs once in the string.
August 28, 2012 at 4:51 am
thanksssssssssssssssss
August 28, 2012 at 4:57 am
but there is one problem
my string is parameter that fiil from one function and function returns '0,0,'',0,'',0'
now how do i do?
August 28, 2012 at 5:11 am
elham_azizi_62 (8/28/2012)
...my string is parameter that fiil from one function and function returns '0,0,'',0,'',0'
now how do i do?
I can only guess what you are trying to say here, it makes no sense in English! Please can you try again?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply