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 2000 Forums
 Transact-SQL (2000)
 Retreiveing a Character Limit using Where Clause

Author  Topic 

DoPLeGaNgA
Starting Member

1 Post

Posted - 2004-03-11 : 15:54:28
Hi!

How can I set a character limit to return values <=60 in a where clause. I'm selecting a field from a table using a where clause that returns field values that are not null, but I also want to limit results to values that are less than 60 characters in legnth. Below is what I have so far. I've tried a few things but I think I may be using the incorrect syntax. I can get the results excluding the null values with the query but I can't seem to figure out how to also exclude values greater than 60 characters. Any help would be greatly appreciated. Thank you!

select NEWVALUE
from AUDITLOG_FIELDLEVEL
where NEWVALUE is not null

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2004-03-11 : 16:07:28
[code]
AND DATALENGTH(NEWVALUE)<=60
[/code]


--Frank
http://www.insidesql.de

Sorry, for editing, but depending on your datatype for that column NEWVALUE you might need to multiply times 2 when the datatype is a unicode datatype.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-03-11 : 16:31:57
I'm not so sure s/he is looking for storage....

[CODE]
USE Northwind
GO

CREATE TABLE myTable99(Col1 char(10), Col2 varchar(10), Col3 nvarchar(10))
GO

INSERT INTO myTable99(Col1, Col2, Col3)
SELECT '12345', '12345', '12345'
GO

SELECT LEN(Col1),LEN(Col2),LEN(Col3)
FROM myTable99

SELECT DATALENGTH(Col1),DATALENGTH(Col2),DATALENGTH(Col3)
FROM myTable99
GO

DROP Table myTable99
GO

[/CODE]



Brett

8-)
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2004-03-12 : 03:01:38
Who knows?
However, the original questioner should now have some ideas for a solution, right?






--Frank
http://www.insidesql.de
Go to Top of Page
   

- Advertisement -