I have benn puzzled by this over the last 2 days, maybe an SQL expert here can help me out.<BR><BR>I have the following table:<BR>==============<BR>Pref<BR>============== <BR>UID int<BR>SMOKE bit<BR>LIVESMOKE bit<BR>PET bit<BR>LIVEPET bit<BR>==============<BR> <BR>I have a record with the following preferences:<BR>smoke: 1<BR>live with smoker: 1<BR>pet: 0<BR>live with pet: 0<BR><BR>how can I write a stored procedure in MS SQL to pull up all rows in the table sorted by the number of matching preferences to the row indicated above?<BR><BR>My initial thought was to xnor the pref which will return 1 on each matching pref but then I run into a problem with sorting the xnor result. <BR><BR>Have anyone done this before? any idea or suggestion? <BR>