Home > Archive > MS SQL Server MSEQ > September 2005 > ALTER COLUMN on a text or ntext field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ALTER COLUMN on a text or ntext field
Paul B

2005-09-21, 11:24 am

Hi,

I'd like to run the following command:

ALTER TABLE cal_respurpose ALTER COLUMN [purpose] varchar(255)

but it falls over because the current [purpose] column is 'text': -

Server: Msg 4928, Level 16, State 1, Line 1
Cannot alter column 'purpose' because it is 'text'.

I can change it through design view in Enterprise manager, after clicking ok on the warning message, but I need to find a way to override this error in Script.

Is there a way I can overide the fact that it is a text column and change it to varchar?

Thanks in advance!

Paul

Paul B

2005-09-21, 11:24 am

Got answer from Aaron Bertrand [SQL Server MVP] on another newsgroup.

EXEC sp_rename 'cal_respurpose.purpose', 'purpose_old', 'COLUMN'

ALTER TABLE cal_respurpose ADD purpose VARCHAR(255)

UPDATE cal_respurpose SET purpose = SUBSTRING(purpose_ol
d, 1, 255)

ALTER TABLE cal_respurpose DROP COLUMN purpose_old

Cheers!


"Paul B" <paul.bunting@archsoftnet.com> wrote in message news:%23J%23SJCsvFHA
.1996@TK2MSFTNGP10.phx.gbl...
Hi,

I'd like to run the following command:

ALTER TABLE cal_respurpose ALTER COLUMN [purpose] varchar(255)

but it falls over because the current [purpose] column is 'text': -

Server: Msg 4928, Level 16, State 1, Line 1
Cannot alter column 'purpose' because it is 'text'.

I can change it through design view in Enterprise manager, after clicking ok on the warning message, but I need to find a way to override this error in Script.

Is there a way I can overide the fact that it is a text column and change it to varchar?

Thanks in advance!

Paul

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com