Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rabisco
Starting Member
15 Posts |
Posted - 2012-02-23 : 18:23:10
|
I have the following codedeclare @myvar varchar(max)declare @code1sku varchar(50)declare @code2sku varchar(50)declare @prereplace varchar(50)declare @postreplace varchar(50)declare @poscode1 intset @myvar = ''declare c1 cursor read_onlyforselect bodytext from documentbodyopen c1fetch next from c1 into @myvarwhile @@fetch_status = 0beginif charindex('code1=',@myvar) > 0 and charindex(code2=',@myvar) = 0beginset @poscode1 = (select patindex('%code1="%', @myvar))set @code1sku = (select substring(@myvar, @poscode1 + 13,7))set @code2sku = (select code2_sku from Linktable where code1_sku = @code1sku)set @prereplace = 'code1="'+@code1sku+'"'set @postreplace = @prereplace+' code2="'+@code2sku+'"'set @myvar = replace(@myvar, @prereplace,@postreplace)update jivedocumentbodyset bodytext = @myvarwhere current of c1endfetch next from c1 into @myvarendclose c1deallocate c1This is what I'm attempting to achieve....for the sample data(This is the bodytext column of the documentbody table) - <body><p><aname="productLink" class="productLink" code1="1463513" >ProductLink</a></p></body>For every paragraph<p></p> , users should enter a value for code1 and code2.The current situation.Users have created some documents which have only values for code1 or code 2The proposed solution.1. A sql job to look through all the rows (bodytext column) of the documentbody table2. Find an occurence of a value for code1,3. Look for the corresponding code2 value in another table4. Update the code2 value where it is missing.So essentially, I'm trying to achieve this...<body><p><aname="productLink" class="productLink" code1="1463513" code2="4567891">ProductLink</a></p></body>Note that some rows have multiple paragrahs . Essentially, the same operation will be carried out on every paragraph where there is one of code1 or code2 missing. Any paragraphs or rows with both code1 or code2 missing, will not be processed.Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-23 : 18:31:48
|
why dont you put this in xml field and do check using exist() function and do update using modify() method?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|