Having trouble using Order by when calling distinct

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Ken (cyyu_tba_at_lycos.com)
Date: 09/23/04


Date: 22 Sep 2004 21:25:21 -0700

What I wanted to do here is to optimize performance by using
getstring. But I wanted same record to listed once and also listed in
order as well. But this code result in error, I think the problem is
to do with the item I use for order by doesnt get selected. I wonder
how I could fix this?

sSQL = "SELECT DISTINCT '<OPTION ' +"
sSQL = sSQL & "Case "
sSQL = sSQL & " WHEN PATINDEX('%,'+ CAST(PKID AS VARCHAR(10))+',%',
',"&trim(strGrp)&",')>0 THEN 'selected'"
sSQL = sSQL & " ELSE '' "
sSQL = sSQL & "END + ' value=' + CAST(PKID AS VARCHAR(10))+ '>' + "
sSQL = sSQL & "FabGroup +'</OPTION>' "

sSQL = sSQL & "FROM vw_opr_fab_gp as sk_main where 1=1 "
sSQL = sSQL + fseason&fYear&fBuyer
sSQL = sSQL & " ORDER BY FabGroup"
                                        
Set rsGrp = Server.CreateObject("ADODB.Recordset")
                        
with rsGrp
        .Open sSQL,Session.Contents("ADOConnection")
        If .State > 0 then
                If Not .EOF and Not .EOF Then
                Response.Write .GetString(2, -1)
                End If
                .Close
        End If
end with
Set rsGrp = Nothing

Ken