hi there
is it possible to have 2 conditions within a switch expression like the
following
=switch(Fields!ReferrerDept.Value = 56, "x Branch",
(Fields!ReferrerDept.Value = 22 and Fields!ReferrerName.Value = 'name'),
"Self Generated - Name",
true, Nothing)
ThanksIn what language? Your code looks very VBish to me (looks like it came
out of a Reporting Services chunk of code actually). In T-SQL, these
kind of conditional expressions are done with a CASE
<http://msdn.microsoft.com/library/e..._ca-co_5t9v.asp>
functions, and yes, as long as it evaluates to a boolean expression,
your individual case conditions can be pretty much as complex as you
like, and you can nest CASE functions, but your result expressions in
each conditional branch need to evaluate to the same datatype.
For example, while I don't really follow what your logic is trying to
achieve, in T-SQL it would be something like: (untested)
SELECT
CASE
WHEN (ReferrerDept = 56) THEN 'x Branch'
WHEN (ReferrerDept = 22 AND ReferrerName = 'name') THEN 'Self
Generated - Name'
ELSE null
END as [MyCol]
FROM MyTable
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Tango wrote:
>hi there
>is it possible to have 2 conditions within a switch expression like the
>following
>=switch(Fields!ReferrerDept.Value = 56, "x Branch",
>(Fields!ReferrerDept.Value = 22 and Fields!ReferrerName.Value = 'name'),
>"Self Generated - Name",
>true, Nothing)
>Thanks
>|||thanks Mike
"Mike Hodgson" wrote:
> In what language? Your code looks very VBish to me (looks like it came
> out of a Reporting Services chunk of code actually). In T-SQL, these
> kind of conditional expressions are done with a CASE
> <http://msdn.microsoft.com/library/e..._ca-co_5t9v.asp>
> functions, and yes, as long as it evaluates to a boolean expression,
> your individual case conditions can be pretty much as complex as you
> like, and you can nest CASE functions, but your result expressions in
> each conditional branch need to evaluate to the same datatype.
> For example, while I don't really follow what your logic is trying to
> achieve, in T-SQL it would be something like: (untested)
> SELECT
> CASE
> WHEN (ReferrerDept = 56) THEN 'x Branch'
> WHEN (ReferrerDept = 22 AND ReferrerName = 'name') THEN 'Self
> Generated - Name'
> ELSE null
> END as [MyCol]
> FROM MyTable
> --
> *mike hodgson*
> blog: http://sqlnerd.blogspot.com
>
> Tango wrote:
>
>
Tuesday, March 20, 2012
quick switch question
Labels:
conditions,
database,
expression,
fieldsreferrerdept,
microsoft,
mysql,
oracle,
server,
sql,
switch,
thefollowingswitch,
thereis,
value
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment