- Q What is an Internal Table?
- Q You are given 7 identical balls and another ball that looks the same as the others but is heavier than them. You can use a balance only two times. How would you identify which is the heavy ball?
- Q Why should i trade forex?
- Q How do you execute a PHP script from the command line?
- Q List r/3 user types?
- Q Which river is known as 'Churni' in ancient times?
- Q Which is considered as the world’s worst industrial disaster ?
- Q How many Airports are in Himachal Pradesh?
- Q What was the ancient name of Bengal?
- Q The train is arriving ___ platform number 4:
- Q What is atopic dermatitis?
Question
Can I have optional parameters to my stored procedures?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Answers
Yes, you can have a stored procedure that has optional parameters. You can do this by setting a default value for
each parameter that you want to make optional. The default value is typically NULL, but it doesn't have to be. Here
is some sample code, ready to test in Query Analyzer:
CREATE PROCEDURE foo
@param1 VARCHAR(32) = NULL,
@param2 INT = NULL
AS
BEGIN
PRINT '-------------------------'
PRINT COALESCE
(
'@param1 = '+@param1,
'@param1 was empty'
)
PRINT COALESCE
(
'@param2 = '+CAST(@param2 AS CHAR(9)),
'@param2 was empty'
)
/*
-- sample usage in a query
SELECT columns FROM table WHERE
(@param1 IS NULL OR column1 = @param1)
AND
(@param2 IS NULL OR column2 = @param2)
*/
END
GO
EXEC foo @param1='bar', @param2=4
EXEC foo @param1='bar'
EXEC foo @param2=4
EXEC foo 'bar',4
EXEC foo 'bar'
EXEC foo
For an Access stored query, you can use the following logic:
PARAMETERS Param1 VARCHAR(32), Param2 INT;
SELECT columns FROM table WHERE
([Param1] IS NULL OR column1 = [Param1])
AND
([Param2] IS NULL OR column2 = [Param2])
Your Comment
each parameter that you want to make optional. The default value is typically NULL, but it doesn't have to be. Here
is some sample code, ready to test in Query Analyzer:
CREATE PROCEDURE foo
@param1 VARCHAR(32) = NULL,
@param2 INT = NULL
AS
BEGIN
PRINT '-------------------------'
PRINT COALESCE
(
'@param1 = '+@param1,
'@param1 was empty'
)
PRINT COALESCE
(
'@param2 = '+CAST(@param2 AS CHAR(9)),
'@param2 was empty'
)
/*
-- sample usage in a query
SELECT columns FROM table WHERE
(@param1 IS NULL OR column1 = @param1)
AND
(@param2 IS NULL OR column2 = @param2)
*/
END
GO
EXEC foo @param1='bar', @param2=4
EXEC foo @param1='bar'
EXEC foo @param2=4
EXEC foo 'bar',4
EXEC foo 'bar'
EXEC foo
For an Access stored query, you can use the following logic:
PARAMETERS Param1 VARCHAR(32), Param2 INT;
SELECT columns FROM table WHERE
([Param1] IS NULL OR column1 = [Param1])
AND
([Param2] IS NULL OR column2 = [Param2])
Your Comment
- 0
- 0
- New Answer
- Contributors: *,
More Software Questions..
What is the inputsplit in map reduce software?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is software configuration management?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What Is Java Api For Xml-based Rpc (jax-rpc)?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How can you implement fine-grained auditing?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is IBM’s simple explanation for Big Data’s four critical features?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is static synchronized method in JDBC API? Give an example?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What does the NULLIF function do?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What happens if a start method is not invoked and the run method is directly invoked?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Should we override finalize method
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
what is the difference between mysql_fetch_array and mysql_fetch_object?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How will XML affect my document links?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Why to use Style Sheets?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are Filters in MVC?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Can you explain Application layer in OSI model?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How to define new testplan attributes?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Which oracle package is used to manage the oracle lock management services?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is marker interface?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What types of partitioning are there for BW?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,