Does SQL have an equivalent to DECODE?
----- Original Message -----
From: "Brandon Whitaker" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 22, 2000 1:25 PM
Subject: Re: Stored Procedure
> >One thing you can't do in a stored procedure is set the ORDER BY to a
> >variable, so you have to dynamically build the statement in your stored
> >procedure.
>
> Au contraire!
> The following was pointed out to me by Oracle ubergenius Thomas Kyte, when
I
> posted the same message to comp.databases.oracle.misc: You CAN do a
dynamic
> ORDER BY ...by using a DECODE. Or whatever SQL Server's equivalent is, if
> not DECODE.
>
> CURSOR testCursor(
> fooVar NUMBER,
> orderBy NUMBER DEFAULT 1)
> IS
> SELECT foo, bar, baz
> FROM fooTable
> WHERE foo = fooVar
> ORDER BY DECODE(orderBy,1,foo,2,bar,3,baz);
>
> Passing 1 (or nothing, as it's a default) would order by FOO, 2 orders by
> BAR, 3 orders by BAZ, etc. I've never worked with SQL Server, but I'm
sure
> there must be something roughly analogous to this.
>
> HTH. HAND.
>
> Brandon Whitaker
> [EMAIL PROTECTED]
> -------
> "It'll get used by the same people using Opera. People dressed in black
> wearing berets."
> - Dave Watts, on Mozilla
> "The net interprets censorship as damage and routes around it."
> - John Gilmore
> "I'm sorry, I can't hear you. God just sat on my Whoopee Cushion."
> - Kibo
>
>
>
> --------------------------------------------------------------------------
----
> Archives: http://www.eGroups.com/list/cf-talk
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.