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
 General SQL Server Forums
 New to SQL Server Programming
 query to bring only records that have 2 char

Author  Topic 

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-05-09 : 14:57:12
I am trying to get all the records where a particular field ( description) has no more that two characters

something like this

select * from
mytable
where description.lenght < 3

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-09 : 14:59:26
[code]SELECT * from Table where datalength(Description) <= 2[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-05-09 : 15:57:49
Depending on the datatype, you will want to use LEN or DATALENGTH as they will return different values. If you have AdventureWorks installed you can use this query or modify it to run against your database:
USE AdventureWorks;
GO
SELECT LEN(Name) AS Length, DATALENGTH(Name) AS DataLen, Name
FROM Production.Product
ORDER BY Name;
GO


EDIT: For got to mention that your Compatability Level may affect the results as well. See sp_dbcmptlevel in BOL.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-10 : 06:17:27
quote:

select * from
mytable
where description.lenght < 3

Thats front end code

Madhivanan

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

- Advertisement -