3 Replies - 647 Views - Last Post: 04 July 2013 - 08:59 AM Rate Topic: -----

#1 frankwright1  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 93
  • Joined: 07-May 12

UPDATE using SELECT

Posted 01 July 2013 - 06:06 AM

Hi

I have the following code to insert into a table, with commas to seperate values:

INSERT INTO  tbltstr2 (main, tret)

SELECT t1.main,
       treeref3 =REPLACE( (SELECT treeref3 AS [data()]
       FROM tbltstr t2
       WHERE t2.main = t1.main
       ORDER BY treeref3
       FOR XML PATH('')
       ), ' ', ', ')
      FROM tbltstr t1
      GROUP BY main



The code continues to clear table tbltstr and repopulate it with fresh data. I would like to use this data to update
a third column in tbltstr2 (trem) in the same way, using commas to separate the data, rather than having multiple rows.
Any pointers?

Thanks
Frank

Is This A Good Question/Topic? 0
  • +

Replies To: UPDATE using SELECT

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,175
  • Joined: 12-June 08

Re: UPDATE using SELECT

Posted 01 July 2013 - 12:27 PM

Okay.. so either add it after line 9 (before line 10)... and make sure the groupby still works, or just do an update or something on the data inserted with only that specific column.
Was This Post Helpful? 0
  • +
  • -

#3 frankwright1  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 93
  • Joined: 07-May 12

Re: UPDATE using SELECT

Posted 04 July 2013 - 02:41 AM

Right thanks, I think I'll Do you mean something like this?

INSERT INTO  tbltstr2 (main, tret)

SELECT t1.main,
       treeref3 =REPLACE( (SELECT treeref3 AS [data()]
       FROM tbltstr t2
       WHERE t2.main = t1.main
       ORDER BY treeref3
       FOR XML PATH('')
       ), ' ', ', ')
      FROM tbltstr t1

*******reset data in tbltstr.treeref3*********

INSERT INTO  tbltstr2 (main, trem)

SELECT t1.main,
       treeref3 =REPLACE( (SELECT treeref3 AS [data()]
       FROM tbltstr t2
       WHERE t2.main = t1.main
       ORDER BY treeref3
       FOR XML PATH('')
       ), ' ', ', ')
      FROM tbltstr t1

      GROUP BY main



This post has been edited by frankwright1: 04 July 2013 - 02:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,175
  • Joined: 12-June 08

Re: UPDATE using SELECT

Posted 04 July 2013 - 08:59 AM

I am not sure what you are doing there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1