emadhu
asked on
If else condition in Sybase 12.5
I would like to code a Stored Procedure depending the on IN params that are passed to the SP
example: EXEC Abc_SP 'Param1'
Note: Param1 is optional
Inside the SP, i would like to check if the Param1 is available
if (Param1 is passed) {
if (Param1 == 'A') {
-- do this
} else {
-- do something else
}
} else {
-- do this
}
How do I code this in Transact SQL Stored Procedure?
example: EXEC Abc_SP 'Param1'
Note: Param1 is optional
Inside the SP, i would like to check if the Param1 is available
if (Param1 is passed) {
if (Param1 == 'A') {
-- do this
} else {
-- do something else
}
} else {
-- do this
}
How do I code this in Transact SQL Stored Procedure?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK, I just reacted to original question "i would like to check if the Param1 is available" and said, that you can't allways know, whether optional parameter was supplied. However, you are right - in most real-life cases you don't need that information.
1 That might be true in theory, but not in practice. We have to be sensible here. Take a real situation, a real parameter, not a theoretical parameter. Eg. sp_who. The parameter is spid. What is the difference between:
2 By deifinition, null is not a value, or more accurately, it means "no value". Therefore it would be completely incorrect for the proc to accept null as a value of any kind. It should only signify that no value was passed. And anyone explicitly passing null means they are passing "no value".
3 Therefore, by definition, null cannot be the default, because the default is a real value.
4 But, if you wanted code that would capture and respond to such a situation (keeping these rules in mind), here it is.
Cheers
Open in new window