Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
KnooKie
Aged Yak Warrior
623 Posts |
Posted - 2001-01-22 : 13:34:33
|
| I am using SQL2000.I have a SELECT statement in an SP that selects 10 fields, however, i want to be able to pass a variable to the SP to determine which field to ORDER BY.Is there a way to do this ?I've tried passing in one of the field names to a variable and then doing ORDER BY @OrderByThisColumn ...nope.I've tried SETting a variable to the above @OrderByThisColumn ...nope.Any ideas/clues would be a great helpThe code...........CREATE PROCEDURE usp_ShareHolders_Main_sel@CompanyCode varchar(4),@OrderByThisColumn varchar(30)ASSELECT H.Fund_Man as Holders, H.Shares as SharesHeld, H.Share_Pric * H.Shares as Value, H.Pcent as SharesOutstanding, H.Shares - H.Shares as ShareChange, C.Reg_Date as ReportDate, 'Register' as Source, ((C.Capital / S.CapTotal) * (H.TotalTot * S.CapTotal)) / C.Capital as SectorWeightingPcent, H.Pcent - (((C.Capital / S.CapTotal) * (H.TotalTot * S.CapTotal)) / C.Capital) as OverUnderWeight, (H.Pcent - (((C.Capital / S.CapTotal) * (H.TotalTot * S.CapTotal)) / C.Capital)) * C.isc as SurplusDeficitFROM Citywatch_Company CInner Join Citywatch_Holders HOn C.Epic = H.EpicInner Join Citywatch_Sector SOn H.Sector = S.Sec_CodeWHERE C.Epic = @CompanyCodeORDER BY <one of the select columns above>Help me please someonePaul |
|
|
|
|
|