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

it go like this ->

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 ?


Re: query order problem 80 80

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....


Also use this for pasting text:

[code=text] ...text here]


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

Re: query order problem 80 80

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.

Re: query order problem 80 80

Ramesh Thank's For your help
It works just fine

Be a part of the DaniWeb community

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