Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ntext field length

Author  Topic 

s2002
Starting Member

49 Posts

Posted - 2009-04-05 : 06:44:47
hi,
Table design

ID PK
Note Ntext

I want to show all records of above table where ntext field length < 200.
I have tried len(note) < 200 but I encounter error.
How could I find ntext field lenght

sincerelym
sam

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-04-05 : 08:47:43
What is the error?convert to varchar & try.
Go to Top of Page

s2002
Starting Member

49 Posts

Posted - 2009-04-05 : 13:58:53
hi
I use this
select * from Post
where LEN(note)< 200

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

sincerely,
sam
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-04-05 : 14:06:29
select * from Post
where len(convert(varchar(200),note))<200
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2009-04-05 : 14:26:58
I'd consider using the DATALENGTH function. Since you're using NTEXT you'll need to divide the result by two.

If you switch from NTEXT to NVARCHAR(MAX) you can use the LEN function.

=================================================
Creating tomorrow's legacy systems today. One crisis at a time.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-06 : 05:49:00
Also note the point specified in SQL Server help file
quote:
ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. For more information, see Using Large-Value Data Types.


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -