SQL Server: Replace characters different than a char in a string using no temporary table -
I have the NVARCHAR (10)
column in a table. It can store any type of Unicode Wire.
I want to change every four which is different in comparison with '1' '0'.
Let's say I do string '012345C18 *' I should get '0100000100'.
I managed to use it in a support table, which is indexed in size from 1 to my column (10), like:
Table Help (IDX INT ) Select test support Select 1 Select Unions 2 Select Unions 3 Select Unions 4 Select Unions 5 Select Unions 6 Unions Selection 7 Federal Selection 8 Unions Selection 9 Unions Selection 10 Announced @myStr VARCHAR (10) Set Insert @myStr = '012345C18 *' Select STUFF ((Select '' + Case (B.Ch) when 'From 1 'then' 1 'remaining' 0 '(SUBSTRING (select A.Val, H.Idx, 1) as Chowdhury' 1,0), 'for XML path (@ Select myStr) Join a Cross Help H) B ('')
This works, but can this be a good way? It looks ugly for a simple update, ignoring the fact that the size of the column can change over time. Also have to walk on SQL> = 2005 .
SQL Bedle
Thanks!
This is a way of doing this with a whistle. In my system, I actually have CTL as CTU's visual name. This technique generates a 10,000 line view with zero reading. ;) Your code works quite well as a post. For this example, I have moved the string into a table, because that is how you are working in the actual system.
Declare @ myStrings table (MyVal varchar (10)); Insert @ myStrings '012345C18 *'; Select All (1) Union All Select (1) Union All Selection (1) Union All Selection (1) Union All Selection (1) Union All Selection (1) Select Union All (1) Union All Selection (1) Association All Selection (1)) as DT (N), E2 (N) (Selection 1 to EA, E1B), - 10 E + 2 or 100 rows as E4 (N) (Selection 1A, B E2), --10E 4 or 10,000 rows max cteTally (N) (more than selection ROW_NUMBER () (Selection zero)) Order from E4) Select STUFF ((Select '' + Case (B.Ch) when '1' then '1' remaining Select '0' end (Select SUBSTRING (A.MyVal, TN, 1) @myStrings Include cteTally T as a cross with Choice where Tamilnadu & lt; LN (AMY)) BP XML path (' '), 1,0,' ')
Comments
Post a Comment