Thursday, March 22, 2012

Duplicate Column

Hi,

I have a column which I need to duplicate with the excat enteries.

I have column name jDateComplete which I need to duplicate with DateComplete.

Can somebody please help me with this?

Thanks,

Aash.

Quote:

Originally Posted by patelaashish

Hi,

I have a column which I need to duplicate with the excat enteries.

I have column name jDateComplete which I need to duplicate with DateComplete.

Can somebody please help me with this?

Thanks,

Aash.


update Table
set jDateComplete = DateComplete|||Hi,

I tried the update statement and it has put NULL values in both of the columns in my table.

Please let me know If I am doing something wrong.

Thanks,

Aash.|||I assumed that one column already had data in it - if that is not the case then update/insert your table as normal

e.g.

update mytable
set col1 = somedata,
col2 = somedata

insert into mytable col1, col2
values(somdata, somdata)|||Hi,

Yes the jDateComplete has got data in it.

Thanks|||assuming your table has an ID column - this will do the trick
substitute ID for your table's primary key

declare @.counter int, @.MaxID int
set @.counter = (select min(id) from mytable)
set @.MaxID = (select max(id) from mytable)

while @.counter <= @.MaxID
begin
update mytable
set jDateComplete = (Select DateComplete from mytable where id = @.counter)
where id = @.counter

set @.counter = @.counter + 1
endsql

No comments:

Post a Comment