Question

How do i loop in t-sql for every row the table has? I have a table, WorkOrder it has two columns: name, name2. Now what I want is the values for the name column, be appended on the name2 column.

So for example, I have this row:

name   |  name2
test   |  test2

I want the name column to be appended on the name2 column so that it looks like this for every row.

name   |  name2
test   |  test test2

How do i do that? thanks

another question:

what if the combination of both columns exceeded the character limit for that column? When that happens I would like to ignore that row, and continue updating the others

Was it helpful?

Solution

You could simply do this:

UPDATE WorkOrder 
SET name2=name1+' '+name2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top