Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Data sorting
Message
 
 
To
21/06/2002 21:05:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00671286
Message ID:
00671303
Views:
27
Try
Select *, SortOrder(color1,color2,color3,color4) AS sortorder ;
   From mytable ;
   ORDER BY sortorder 

...
FUNCTION SortOrder(tcColor1,tcColor2,tcColor3,tcColor4)
RETURN ;
  IIF(tcColor1="blue" or tcColor2="blue" or tcColor3 ="blue" or tcColor4=="blue", "1", "2") + ;
  IIF(tcColor1="green" or tcColor2="green" or tcColor3 ="green" or tcColor4=="green", "1", "2") + ;
  IIF(tcColor1="yellow" or tcColor2="yellow" or tcColor3 ="yellow" or tcColor4=="yellow", "1", "2") + ;
  IIF(tcColor1="white" or tcColor2="white" or tcColor3 ="white" or tcColor4=="white", "1", "2") + ;
  IIF(tcColor1="black" or tcColor2="black" or tcColor3 ="black" or tcColor4=="black", "1", "2") + ;
  IIF(tcColor1="other" or tcColor2="other" or tcColor3 ="other" or tcColor4=="other", "1", "2")
Instead of using UDF you can include those IIF's directly in the query.

>I have a table have the follow fields :
>
>id, color1,color2,color3,color4
>
>
>I need to sort the the records by color. which means record have the same color should group together. eg.
>
>id,color1,color2,color3,color4
>
>1,black
>2,blue,green
>3,yellow,green,blue
>4,green,blue
>5,white
>
>so, the result should be
>
>2,blue,green
>4,green,blue
>3,yellow,green,white,yellow
>5,white
>4,black
>
>Because record 2,4 have the colors blue & green, and record 3 have green, and record 5 have notting.
>
>Anyone have idea in how the program so like?
>
>TIA.
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform