Update with select replace

  • I'm trying to update the bodytext column of the documentbody table for rows where this string is found.

    <body><p><aname="productLink" class="productLink" code1="1463513" >ProductLink</a></p></body>

    with

    <body><p><aname="productLink" class="productLink" code1="1463513" code2="4567891">ProductLink</a></p></body>

    the update statement below, updates every row,....

    declare @myvar varchar(max)

    declare @code1sku varchar(50)

    declare @code2sku varchar(50)

    declare @prereplace varchar(50)

    declare @postreplace varchar(50)

    declare @poscode1 int

    set @myvar = ''

    declare c1 cursor read_only

    for

    select bodytext from documentbody

    open c1

    fetch next from c1 into @myvar

    while @@fetch_status = 0

    begin

    if charindex('code1=',@myvar) > 0 and charindex(code2=',@myvar) = 0

    begin

    set @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 documentbody

    set bodytext = @myvar

    where @prereplace is not null

    end

    fetch next from c1 into @myvar

    end

    close c1

    deallocate c1

    What I'm trying to achieve is to update only every row where @prereplace is not empty.

    please help.

  • Looks like @prereplace is set to 'code1=' when other dependent @vars are null, as you're concatenating variables and a string.

    So replace:

    update documentbody

    set bodytext = @myvar

    where @prereplace is not null

    with:

    update documentbody

    set bodytext = @myvar

    where @prereplace <> 'code1='

    What errors (if any) or errant behaviour are you getting at the moment?

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • And why the cursor? You should be able to this in a single update statement without too much trouble.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • derek.colley (2/21/2012)


    Looks like @prereplace is set to 'code1=' when other dependent @vars are null, as you're concatenating variables and a string.

    So replace:

    update documentbody

    set bodytext = @myvar

    where @prereplace is not null

    with:

    update documentbody

    set bodytext = @myvar

    where @prereplace <> 'code1='

    What errors (if any) or errant behaviour are you getting at the moment?

    All the rows are getting updated, even the ones what were originally empty.

  • If you want some real help with please read the first link in my signature. It will explain how to ask questions and what kind of information to post.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • It's updating all rows because what you are basically saying is for every row, set the bodytext equal to 'code=1' and concatenate other parameters onto it. If those other parameters are null, you'd still be left with code=1. So your conditional logic, your 'IF' statement, will still update the row, because @myvar does not equal NULL!

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • derek.colley (2/21/2012)


    It's updating all rows because what you are basically saying is for every row, set the bodytext equal to 'code=1' and concatenate other parameters onto it. If those other parameters are null, you'd still be left with code=1. So your conditional logic, your 'IF' statement, will still update the row, because @myvar does not equal NULL!

    Thanks.

    Here lies my problem....

    for some rows, @myvar will be Null or blank ' ', for some others they will have strings other than the ones I'm looking for and will not need updating.

    I had assumed that the conditional logic

    "if charindex('code1=',@myvar) > 0 and charindex('code2=',@myvar) = 0" will limit rows to be updated to those which contained the strings I was looking for.

  • rabisco (2/21/2012)


    derek.colley (2/21/2012)


    It's updating all rows because what you are basically saying is for every row, set the bodytext equal to 'code=1' and concatenate other parameters onto it. If those other parameters are null, you'd still be left with code=1. So your conditional logic, your 'IF' statement, will still update the row, because @myvar does not equal NULL!

    Thanks.

    Here lies my problem....

    for some rows, @myvar will be Null or blank ' ', for some others they will have strings other than the ones I'm looking for and will not need updating.

    I had assumed that the conditional logic

    "if charindex('code1=',@myvar) > 0 and charindex('code2=',@myvar) = 0" will limit rows to be updated to those which contained the strings I was looking for.

    There are a number of problems with the code you posted. Your update is just not even close to what you want.

    update documentbody

    set bodytext = @myvar

    where @prereplace is not null

    Each trip through your cursor it will update the ENTIRE table if @prereplace is null.

    More than anything else there is no need for a cursor. I will ask again for ddl and sample data.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (2/21/2012)


    rabisco (2/21/2012)


    derek.colley (2/21/2012)


    It's updating all rows because what you are basically saying is for every row, set the bodytext equal to 'code=1' and concatenate other parameters onto it. If those other parameters are null, you'd still be left with code=1. So your conditional logic, your 'IF' statement, will still update the row, because @myvar does not equal NULL!

    Thanks.

    Here lies my problem....

    for some rows, @myvar will be Null or blank ' ', for some others they will have strings other than the ones I'm looking for and will not need updating.

    I had assumed that the conditional logic

    "if charindex('code1=',@myvar) > 0 and charindex('code2=',@myvar) = 0" will limit rows to be updated to those which contained the strings I was looking for.

    There are a number of problems with the code you posted. Your update is just not even close to what you want.

    update documentbody

    set bodytext = @myvar

    where @prereplace is not null

    Each trip through your cursor it will update the ENTIRE table if @prereplace is null.

    More than anything else there is no need for a cursor. I will ask again for ddl and sample data.

    Thanks for your help.

    ddl is below..

    CREATE TABLE [dbo].[documentBody](

    [bodyID] [bigint] NOT NULL,

    [bodyText] [ntext] NULL,

    [fileSize] [int] NULL,

    [contentType] [varchar](100) NULL)

    Sample data is below...

    SELECT '1001',' ','46782','application/pdf', UNION ALL

    SELECT '1002',' ','293380','application/vnd.openxmlformats-officedocument.presentationml', UNION ALL

    SELECT '1003',' ','412484','application/pdf', UNION ALL

    SELECT '1004',' ','5939','application/pdf', UNION ALL

    SELECT '1005',' ','861053','application/pdf', UNION ALL

    SELECT '1006',' ','1692014','application/pdf', UNION ALL

    SELECT '1007',' <body><p><a name="productLink" class="productLink" code1="1815000" href="">sku1</a></p></body>',' ',' ', UNION ALL

    SELECT '1008','<body><p><a name="productLink" class="productLink" code1="1833439" href="">sku2</a></p></body> ',' ',' ', UNION ALL

    SELECT '1009',' <body><p><a name="productLink" class="productLink code1="1833439" href="" uid="13298529604731501">sku3</a></p><p><a name="productLink" class="productLink" code1="1743011" href="">sku4</a></p></body>',' ',' ', UNION ALL

    SELECT '1010','<body><p><a name="productLink" class="productLink code1="1498235" href="" uid="13298535612357259">sku5</a></p><p><a name="productLink" class="productLink" code1="1841793" href="">sku6</a></p></body> ',' ',' ', UNION ALL

  • Each trip through your cursor it will update the ENTIRE table if @prereplace is null.

    More than anything else there is no need for a cursor. I will ask again for ddl and sample data.

    I have added the ddl and sample data.

    I have been able to use this to update each row in my cursor...

    update jivedocumentbody

    set bodytext = @myvar

    where current of c1

    It gives my close to what I want. The only issue I have now is rows which have more than one paragraph ()

  • rabisco (2/22/2012)


    Each trip through your cursor it will update the ENTIRE table if @prereplace is null.

    More than anything else there is no need for a cursor. I will ask again for ddl and sample data.

    I have added the ddl and sample data.

    I have been able to use this to update each row in my cursor...

    update jivedocumentbody

    set bodytext = @myvar

    where current of c1

    It gives my close to what I want. The only issue I have now is rows which have more than one paragraph ()

    There really is no need for a cursor. Cursors are one of the worst constructs in t-sql for performance. This update can be accomplished in a single update statement. I will help but you have to post enough information for me to be able to help.

    The sample data is not valid. It is full of syntax errors. You are missing a table (Linktable) and sample data for that one. The other piece of information is a clear description of what you want this update to do.

    As a side note you should not use the text or ntext datatypes. They are deprecated. You should instead use varchar(max) and nvarchar(max) respectively. http://msdn.microsoft.com/en-us/library/ms187993.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • There really is no need for a cursor. Cursors are one of the worst constructs in t-sql for performance. This update can be accomplished in a single update statement. I will help but you have to post enough information for me to be able to help.

    The sample data is not valid. It is full of syntax errors. You are missing a table (Linktable) and sample data for that one. The other piece of information is a clear description of what you want this update to do.

    As a side note you should not use the text or ntext datatypes. They are deprecated. You should instead use varchar(max) and nvarchar(max) respectively.

    Thanks Sean.Lange - I will post the missing data shortly.

  • rabisco (2/22/2012)


    There really is no need for a cursor. Cursors are one of the worst constructs in t-sql for performance. This update can be accomplished in a single update statement. I will help but you have to post enough information for me to be able to help.

    The sample data is not valid. It is full of syntax errors. You are missing a table (Linktable) and sample data for that one. The other piece of information is a clear description of what you want this update to do.

    As a side note you should not use the text or ntext datatypes. They are deprecated. You should instead use varchar(max) and nvarchar(max) respectively.

    Thanks Sean.Lange - I will post the missing data shortly.

    This is the requested data...

    linktable ddl

    CREATE TABLE [dbo].[Linktable](

    [id] [bigint] IDENTITY(1,1) NOT NULL,

    [part_ref] [bigint] NOT NULL,

    [code1_sku] [varchar](255) NULL,

    [code2_sku] [varchar](255) NULL)

    linktable sample data

    SELECT '1','11259','1595501','83K3087', UNION ALL

    SELECT '2','11260','1595474','83K3074', UNION ALL

    SELECT '3','11261','1727495','66F9349', UNION ALL

    SELECT '4','11262','1727584','66F9341', UNION ALL

    SELECT '5','11263','1728200','66F9331', UNION ALL

    SELECT '6','11264','1729014','66F9330', UNION ALL

    SELECT '7','11265','1729156','66F9347', UNION ALL

    SELECT '8','11266','1730135','66F9343', UNION ALL

    SELECT '9','11267','1730185','66F9333', UNION ALL

    SELECT '10','11268','1730523','66F9342', UNION ALL

    SELECT '11','11269','1732360','66F9334', UNION ALL

    SELECT '12','11270','1732364','66F9344', UNION ALL

    SELECT '13','11271','1732413','66F9335', UNION ALL

    SELECT '14','11272','1732423','66F9345', UNION ALL

    SELECT '15','11273','1741637','02F6689', UNION ALL

    SELECT '16','11274','1741646','02F6675', UNION ALL

    SELECT '17','11275','1741660','02F6727', UNION ALL

    SELECT '18','11276','1741667','02F6732', UNION ALL

    SELECT '19','11277','1741673','02F6728', UNION ALL

    SELECT '20','11278','1741675','02F6763', UNION ALL

    Also use the amended ddl for the documentbody table...

    using the amended ddl

    CREATE TABLE [dbo].[documentBody](

    [bodyID] [bigint] NOT NULL,

    [bodyText] [ntext] NULL)

    I'm providing the documentbody sample data obtained with

    SELECT 'SELECT '

    + QUOTENAME(bodyid,'''')+','

    + cast(bodytext as nvarchar(max))+','

    FROM documentbody

    SELECT '1000', , UNION ALL

    SELECT '1001', , UNION ALL

    SELECT '1002', , UNION ALL

    SELECT '1003', , UNION ALL

    SELECT '1004', , UNION ALL

    SELECT '1005', , UNION ALL

    SELECT '1006', , UNION ALL

    SELECT '1007',<body><p><a name="productLink" class="productLink" code1="1815000" href="">sku1</a></p></body>, UNION ALL

    SELECT '1008',<body><p><a name="productLink" class="productLink" code1="1833439" href="">sku2</a></p></body> , UNION ALL

    SELECT '1009',<body><p><a name="productLink" class="productLink code1="1833439" href="" uid="13298529604731501">sku3</a></p><p><a name="productLink" class="productLink" code1="1743011" href="">sku4</a></p></body>, UNION ALL

    SELECT '1010',<body><p><a name="productLink" class="productLink code1="1498235" href="" uid="13298535612357259">sku5</a></p><p><a name="productLink" class="productLink" code1="1841793" href="">sku6</a></p></body> ,UNION ALL

    What I'm trying accomplish is this.

    The ideal.

    For every paragraph , 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 2

    The proposed solution.

    1. A sql job to look through all the rows (bodytext column) of the documentbody table

    2. Find an occurence of a vale for code1,

    3. Look for the corresponding code2 value in the link table

    4. Update the code2 value where it is missing.

    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.

    I hope this makes it clearer.

    Thanks again.

  • rabisco (2/22/2012)


    rabisco (2/22/2012)


    There really is no need for a cursor. Cursors are one of the worst constructs in t-sql for performance. This update can be accomplished in a single update statement. I will help but you have to post enough information for me to be able to help.

    The sample data is not valid. It is full of syntax errors. You are missing a table (Linktable) and sample data for that one. The other piece of information is a clear description of what you want this update to do.

    As a side note you should not use the text or ntext datatypes. They are deprecated. You should instead use varchar(max) and nvarchar(max) respectively.

    Thanks Sean.Lange - I will post the missing data shortly.

    This is the requested data...

    linktable ddl

    CREATE TABLE [dbo].[Linktable](

    [id] [bigint] IDENTITY(1,1) NOT NULL,

    [part_ref] [bigint] NOT NULL,

    [code1_sku] [varchar](255) NULL,

    [code2_sku] [varchar](255) NULL)

    linktable sample data

    SELECT '1','11259','1595501','83K3087', UNION ALL

    SELECT '2','11260','1595474','83K3074', UNION ALL

    SELECT '3','11261','1727495','66F9349', UNION ALL

    SELECT '4','11262','1727584','66F9341', UNION ALL

    SELECT '5','11263','1728200','66F9331', UNION ALL

    SELECT '6','11264','1729014','66F9330', UNION ALL

    SELECT '7','11265','1729156','66F9347', UNION ALL

    SELECT '8','11266','1730135','66F9343', UNION ALL

    SELECT '9','11267','1730185','66F9333', UNION ALL

    SELECT '10','11268','1730523','66F9342', UNION ALL

    SELECT '11','11269','1732360','66F9334', UNION ALL

    SELECT '12','11270','1732364','66F9344', UNION ALL

    SELECT '13','11271','1732413','66F9335', UNION ALL

    SELECT '14','11272','1732423','66F9345', UNION ALL

    SELECT '15','11273','1741637','02F6689', UNION ALL

    SELECT '16','11274','1741646','02F6675', UNION ALL

    SELECT '17','11275','1741660','02F6727', UNION ALL

    SELECT '18','11276','1741667','02F6732', UNION ALL

    SELECT '19','11277','1741673','02F6728', UNION ALL

    SELECT '20','11278','1741675','02F6763', UNION ALL

    Also use the amended ddl for the documentbody table...

    using the amended ddl

    CREATE TABLE [dbo].[documentBody](

    [bodyID] [bigint] NOT NULL,

    [bodyText] [ntext] NULL)

    I'm providing the documentbody sample data obtained with

    SELECT 'SELECT '

    + QUOTENAME(bodyid,'''')+','

    + cast(bodytext as nvarchar(max))+','

    FROM documentbody

    SELECT '1000', , UNION ALL

    SELECT '1001', , UNION ALL

    SELECT '1002', , UNION ALL

    SELECT '1003', , UNION ALL

    SELECT '1004', , UNION ALL

    SELECT '1005', , UNION ALL

    SELECT '1006', , UNION ALL

    SELECT '1007',<body><p><a name="productLink" class="productLink" code1="1815000" href="">sku1</a></p></body>, UNION ALL

    SELECT '1008',<body><p><a name="productLink" class="productLink" code1="1833439" href="">sku2</a></p></body> , UNION ALL

    SELECT '1009',<body><p><a name="productLink" class="productLink code1="1833439" href="" uid="13298529604731501">sku3</a></p><p><a name="productLink" class="productLink" code1="1743011" href="">sku4</a></p></body>, UNION ALL

    SELECT '1010',<body><p><a name="productLink" class="productLink code1="1498235" href="" uid="13298535612357259">sku5</a></p><p><a name="productLink" class="productLink" code1="1841793" href="">sku6</a></p></body> ,UNION ALL

    What I'm trying accomplish is this.

    The ideal.

    For every paragraph , 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 2

    The proposed solution.

    1. A sql job to look through all the rows (bodytext column) of the documentbody table

    2. Find an occurence of a vale for code1,

    3. Look for the corresponding code2 value in the link table

    4. Update the code2 value where it is missing.

    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.

    I hope this makes it clearer.

    Thanks again.

    Hey Sean, what was I provided enough for you to go on?

    Thanks.

  • rabisco (2/28/2012)


    What I'm trying accomplish is this.

    The ideal.

    For every paragraph , 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 2

    The proposed solution.

    1. A sql job to look through all the rows (bodytext column) of the documentbody table

    2. Find an occurence of a vale for code1,

    3. Look for the corresponding code2 value in the link table

    4. Update the code2 value where it is missing.

    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.

    I hope this makes it clearer.

    Thanks again.

    Hey Sean, what was I provided enough for you to go on?

    Thanks.

    What I was really hoping you would do is to read the details in my post. Your samples are full of syntax errors. Since you are unable or not willing to make this easy for somebody to help I went ahead and formatted your sample data so it can be easily consumed.

    CREATE TABLE [dbo].[Linktable](

    [id] [bigint] IDENTITY(1,1) NOT NULL,

    [part_ref] [bigint] NOT NULL,

    [code1_sku] [varchar](255) NULL,

    [code2_sku] [varchar](255) NULL)

    go

    insert Linktable

    SELECT 11259,'1595501','83K3087' UNION ALL

    SELECT 11260,'1595474','83K3074' UNION ALL

    SELECT 11261,'1727495','66F9349' UNION ALL

    SELECT 11262,'1727584','66F9341' UNION ALL

    SELECT 11263,'1728200','66F9331' UNION ALL

    SELECT 11264,'1729014','66F9330' UNION ALL

    SELECT 11265,'1729156','66F9347' UNION ALL

    SELECT 11266,'1730135','66F9343' UNION ALL

    SELECT 11267,'1730185','66F9333' UNION ALL

    SELECT 11268,'1730523','66F9342' UNION ALL

    SELECT 11269,'1732360','66F9334' UNION ALL

    SELECT 11270,'1732364','66F9344' UNION ALL

    SELECT 11271,'1732413','66F9335' UNION ALL

    SELECT 11272,'1732423','66F9345' UNION ALL

    SELECT 11273,'1741637','02F6689' UNION ALL

    SELECT 11274,'1741646','02F6675' UNION ALL

    SELECT 11275,'1741660','02F6727' UNION ALL

    SELECT 11276,'1741667','02F6732' UNION ALL

    SELECT 11277,'1741673','02F6728' UNION ALL

    SELECT 11278,'1741675','02F6763'

    go

    CREATE TABLE [dbo].[documentBody](

    [bodyID] [bigint] NOT NULL,

    [bodyText] varchar(max) NULL)

    go

    insert documentBody

    SELECT 1000, null UNION ALL

    SELECT 1001, null UNION ALL

    SELECT 1002, null UNION ALL

    SELECT 1003, null UNION ALL

    SELECT 1004, null UNION ALL

    SELECT 1005, null UNION ALL

    SELECT 1006, null UNION ALL

    SELECT 1007, '<body>

    <a name="productLink" class="productLink" code1="1815000" href="">sku1</a></body>' UNION ALL

    SELECT 1008, '<body>

    <a name="productLink" class="productLink" code1="1833439" href="">sku2</a></body>' UNION ALL

    SELECT 1009, '<body>

    <a name="productLink" class="productLink code1="1833439" href="" uid="13298529604731501">sku3</a>

    <a name="productLink" class="productLink" code1="1743011" href="">sku4</a></body>' UNION ALL

    SELECT 1010, '<body>

    <a name="productLink" class="productLink code1="1498235" href="" uid="13298535612357259">sku5</a>

    <a name="productLink" class="productLink" code1="1841793" href="">sku6</a></body>'

    It is still totally unclear to me what you are trying to do. What would be the desired result based on this sample data?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply