Hii
I Have Facing with Order problem
i try to query From Table

it go like this ->

SELECT * FROM Client
WHERE (ClientName LIKE 'X%') OR (ClientName LIKE '%[ ]X%')

It mean give me all clients that start Whit X Letter And Included MiddleName If There is And Last Name. but With Out Ordering!!

And i need to Order it!!
first by Name after it by MiddleName and by LastName...

for example -> ClientName
Erorn Mikel Bon Joi
Jack clint cary
Erorn Mikel Bon Jacov
mohamd abo jaml habdalhaa
jaber mahmoud ben saber

now query all names that Start With 'J'!

result need to look like this
1. Jack clint cary
2. jaber mahmoud ben saber
3. mohamd abo jaml habdalhaa
4. Erorn Mikel Bon Jacov
5. Erorn Mikel Bon Joi

i don't know how to order it,
Someon Have an idea how to start ?

eyal.c

Recommended Answers

All 3 Replies

I cant distinguish between first, middle, and last names in the sample you provided so I can't answer your question.

Please use code tags when posting queries:

[code=sql] ...query here....

[/code]

Also use this for pasting text:

[code=text] ...text here]

[/code]

Use the text paste to line up columns with their column names and values.

Try like this

SELECT * FROM ClientWHERE (ClientName LIKE 'Anne%') OR (ClientName LIKE '%[ ]Anne%')
ORDER By  PATINDEX ( 'Anne%', ClientName) DESC
, PATINDEX ( '%[ ]Anne%', ClientName)

Here replace the name 'Anne' whatever you want.

Ramesh Thank's For your help
It works just fine
thank's

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.