Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by parameter

Status
Not open for further replies.

digimortal

Programmer
Oct 12, 2003
28
TR
I wrote a simple query (not a storedproc) with an order by but it does not work :(

SELECT *
FROM EventsL
WHERE (Door = 'yemekhane') AND (Site LIKE @Site) AND (CONVERT(CHAR(10), DTime, 110) = @Tar)

ORDER BY @Ord

I tried things like

SELECT *
FROM EventsL
WHERE (Door = 'yemekhane') AND (Site LIKE @Site) AND (CONVERT(CHAR(10), DTime, 110) = @Tar)
CASE WHEN @Ord is null THEN CHName END

and this:
SELECT *
FROM EventsL
WHERE (Door = 'yemekhane') AND (Site LIKE @Site) AND (CONVERT(CHAR(10), DTime, 110) = @Tar)
Order By IsNull(@Ord,CHName)

but none of them worked..

Thnx in advance...
 
What data type is @ord and what values are you passing in? If you are trying to pass in a column name that you want to order by then you need to use dynamic sql.

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top