Joel writes "OS: Win 2000 ad. Serverdb: SQL 2000I am attempting to create a dynamic order clause in a stored procedure. I followed Garth's example on how to create a Dynamic "order by" clause in a stored procedure, however I get the error message "Syntax error converting datetime from character string" when I attempt to order by a non-numeric column. I.E. If I order by "DateOfBirth" (which is a DateTime), it works fine. If I order by "Name", I get the error.Here's my stored proc... maybe I'm missing something.CREATE procedure usp_PatientSearch @PatientName VarChar (30), @PatientSSN VarChar(9), @SearchOrder IntAS Begin if (@PatientSSN= "") select FullName, pkPatient, FMPSSN, DOB, LastBranchOfService from tblPatient where tblPatient.FullName like @PatientName + '%' order by case when @SearchOrder = 1 then FullName when @SearchOrder = 2 then FMPSSN when @SearchOrder = 3 then DOB else FullName end desc else select FullName, pkPatient, FMPSSN, DOB, LastBranchOfService from tblPatient where tblPatient.PatientSSN like @PatientSSN + '%' order by case when @SearchOrder = 1 then FullName when @SearchOrder = 2 then FMPSSN when @SearchOrder = 3 then DOB else FullName end desc EndGO
Thanks a lot for any help-- Joel"