Altering the following Source:
select character_maximum_length
from information_schema.columns
where table_name = 'emailtb' AND column_name='emailbody'
will get you the length.
in your context:
if not exists (select name from syscolumns where name = 'emailbody' and id = OBJECT_ID('emailtb') and xtype = 167 and [length] = (select character_maximum_length from information_schema.columns where table_name = 'emailtb' AND column_name='emailbody'))
ALTER TABLE emailtb ALTER COLUMN emailbody nvarchar(max)
quick explanation:
An information schema view is one of several methods SQL Server provides for obtaining metadata. Information schema views provide an internal, system table-independent view of the SQL Server metadata. Information schema views enable applications to work correctly although significant changes have been made to the underlying system tables. The information schema views included in SQL Server comply with the ISO standard definition for the INFORMATION_SCHEMA.
More about information_schema can be found in this MSDN article.