Here's a model but it is still limited to single column, but resists the datatype pitfalls CREATE PROCEDURE gettheesorted (@sortorder char(12) = 'ANY', @sortdirection char(2) = 'UP')ASSET NOCOUNT ONIF @sortdirection = 'UP' ---MAIN IFBEGIN ---main ifSELECT X.fbompart, X.fbomdesc, Z.fvendno, X.jsource, Z.company, X.fpono, X.factqty, X.fbominum, Y.jvar FROM (tables X,Y,Z in some form)ORDER BY case @sortorder when 'part' then X.fbompart else null end asc, case @sortorder when 'descrip' then X.fbomdesc else null end asc, case @sortorder when 'vendor' then Z.fvendno else null end asc, case @sortorder when 'source' then X.jsource else null end asc, case @sortorder when 'company' then Z.company else null end asc, case @sortorder when 'pono' then X.fpono else null end asc, case @sortorder when 'actqty' then X.factqty else null end asc, case @sortorder when 'bomitemno' then X.fbominum else null end asc, case @sortorder when 'variance' then Y.jvar else null end asc END ---main ifELSE ---MAIN IF This is implimented simply to allow two dynamic sort directions without using dynamic SQLBEGIN ---main ifSELECT X.fbompart, X.fbomdesc, Z.fvendno, X.jsource, Z.company, X.fpono, X.factqty, X.fbominum, Y.jvar FROM (tables X,Y,Z in some form)ORDER BY case @sortorder when 'part' then X.fbompart else null end desc, case @sortorder when 'descrip' then X.fbomdesc else null end desc, case @sortorder when 'vendor' then Z.fvendno else null end desc, case @sortorder when 'source' then X.jsource else null end desc, case @sortorder when 'company' then Z.company else null end desc, case @sortorder when 'pono' then X.fpono else null end desc, case @sortorder when 'actqty' then X.factqty else null end desc, case @sortorder when 'bomitemno' then X.fbominum else null end desc, case @sortorder when 'variance' then Y.jvar else null end desc END ---main if
Voted best SQL forum nickname...."Tutorial-D"