Are there any alternatives to 15 if...else...statements in SQL Server
Programming. If so do they scale better and/or provide performance gains?
Thx
MarcMost likely, but it is a bit hard to come up with a solution unless you
provide us with some more specifics of your problem. (See
www.apsfaq.com/5006)
Jacco Schalkwijk
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:8C3457C2-7FA1-454E-B2B0-4F9D4DB0A7DC@.microsoft.com...
> Are there any alternatives to 15 if...else...statements in SQL Server
> Programming. If so do they scale better and/or provide performance gains?
> Thx
> Marc|||it's hypothethical.
I know I will have this problem in a few months and was hoping to guide
myself to a better/different solution.
say for example ages if you are 20 do something, if you are 25 do something
etc etc.
I know the answer is probably the CASE Stmt which is fine but is it hot on
performance?|||Hi
You can use CASE structure if you want.
best Regards,
Chandra
http://chanduas.blogspot.com/
---
*** Sent via Developersdex http://www.examnotes.net ***|||CASE most likely performs better than doing a number of IF...ELSEs. But in
the end the finer details of performance all depends on your particular
problem and data.
Jacco Schalkwijk
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:66F90280-5A66-49C1-95BF-BCFA50741A60@.microsoft.com...
> it's hypothethical.
> I know I will have this problem in a few months and was hoping to guide
> myself to a better/different solution.
> say for example ages if you are 20 do something, if you are 25 do
> something
> etc etc.
> I know the answer is probably the CASE Stmt which is fine but is it hot on
> performance?|||Hi
Another option may be a lookup table.
As Itzik says "Think outside the box"
John
"marcmc" wrote:
> it's hypothethical.
> I know I will have this problem in a few months and was hoping to guide
> myself to a better/different solution.
> say for example ages if you are 20 do something, if you are 25 do somethin
g
> etc etc.
> I know the answer is probably the CASE Stmt which is fine but is it hot on
> performance?|||You can use the Case statement which can help when breaking down your age
example. Take a look at the following example:
SELECT title, price,
Budget = CASE price
WHEN price > 20.00 THEN 'Expensive'
WHEN price BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN price < 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END,
FROM titles
CASE expressions bring a vast degree of power and control to SQL Server
programmers. A working knowledge of CASE expressions can make accessing and
updating SQL Server data easier and perhaps, even more efficient.
Additionally, CASE expressions enable more work to be accomplished using a
single SQL statement, which should also improve efficiency and decrease
development time. As such, CASE expressions should be a component of every
SQL Server developer’s arsenal of programming techniques.
For more information go here which gives some good simplistic examples.
http://www.craigsmullins.com/ssu_0899.htm
"marcmc" wrote:
> Are there any alternatives to 15 if...else...statements in SQL Server
> Programming. If so do they scale better and/or provide performance gains?
> Thx
> Marc|||You are really going to have to give more information. Like what do you
mean by "do something" Case is an scalar expression, so you cannot use is
as a flow control mechanism. If you mean using it like a switch case in VB,
to replace if...else constructs then T-SQL is pretty weak that way, though
it isn't meant not to be.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:66F90280-5A66-49C1-95BF-BCFA50741A60@.microsoft.com...
> it's hypothethical.
> I know I will have this problem in a few months and was hoping to guide
> myself to a better/different solution.
> say for example ages if you are 20 do something, if you are 25 do
> something
> etc etc.
> I know the answer is probably the CASE Stmt which is fine but is it hot on
> performance?
Wednesday, March 7, 2012
Quick Question
Labels:
alternatives,
database,
microsoft,
mysql,
oracle,
performance,
provide,
scale,
server,
serverprogramming,
sql,
statements
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment