SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to change a column Size
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

deanglen
Yak Posting Veteran

64 Posts

Posted - 07/23/2012 :  08:54:58  Show Profile  Reply with Quote
Hi

In a table called Order I have a column called Notes that currently shows

Notes (ntext, null)

If I wanted to change this to 200 characters what would the script be?

I tried ALTER TABLE Order MODIFY Notes varchar(200)

But I can't get it to work.

khtan
In (Som, Ni, Yak)

Singapore
17642 Posts

Posted - 07/23/2012 :  09:11:02  Show Profile  Reply with Quote
ALTER TABLE Order MODIFY ALTER COLUMN Notes varchar(200)



KH
Time is always against us

Go to Top of Page

deanglen
Yak Posting Veteran

64 Posts

Posted - 07/23/2012 :  10:09:15  Show Profile  Reply with Quote
Hi

Tried that but I think there are some columns where there are already more than 200 characters.

Msg 8152, Level 16, State 10, Line 1
String or binary data would be truncated.
The statement has been terminated.

So I need to alter those records that are 200 or more I guess?

I tried

SELECT *
FROM Order
WHERE LEN(Notes) >200;

But get this

Msg 8116, Level 16, State 1, Line 1
Argument data type ntext is invalid for argument 1 of len function.

Any ideas?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/23/2012 :  10:12:28  Show Profile  Reply with Quote
use datalength


SELECT *
FROM Order
WHERE DATALENGTH(Notes) >200


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

deanglen
Yak Posting Veteran

64 Posts

Posted - 05/03/2013 :  06:12:19  Show Profile  Reply with Quote
Brilliant! thanks worked fine
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/03/2013 :  06:18:43  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000