Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am trying to match 2 strings with char_length - doesnt work!

Status
Not open for further replies.

Centrox

Programmer
May 12, 2005
4
SE
Hi,

I am trying to find which authors that have the same amount characters in their first NAME as they have in their last name.

etc Steven Thomas has 6 characters in his first and last name.

I am trying, but it doesn't work. When I use:

select FNAME, LNAME,
from author
where char_length(FNAME) = char_length(LNAME);


It lists all authors available! There is something missing here, what I am doing wrong?

thanks!
 
Maybe this will work,

select FNAME, LNAME,
from author
where LEN(FNAME) = LEN(LNAME);

Drew
 
There is no such function as char_length in SQL Server - as Drew says, you use LEN.

Your query should return an error, not a list of all authors. Are you sure you are using SQL Server?

--James
 
no I am using mimer, but that forumw as empty. No i should use substring or something I think. I have no idea.
 
Posting in a SQL Server forum will give you a SQL Server solution, which we've given you.

Having never used mimer I don't know what the manuals are like but have you tried looking in them?

--James
 
what are the datatypes of the two columns?

if they are both CHAR(50) then CHAR_LENGTH will return 50 for both, and you will get all rows returned

however, if they are VARCHAR(50) then CHAR_LENGTH will
give the actual values as you desire

so if they are CHAR, you need to use CHAR_LENGTH(TRIM(field))

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top