Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Procedure Parameter Issue

Author  Topic 

saran_d28
Starting Member

36 Posts

Posted - 2009-10-28 : 09:18:01
Hi,

My table have 23 Columns. I want to retrive only 9 columns from the table based on the input parameters of the Stored Procedure.

For Example
Table(T1) have 3 columns(c1, c2, c3) and the datas are look like.

c1 c2 c3
1 A 01-jan-2009
2 B 02-jan-2009
3 C 03-jan-2009
and stored procedure have 3 input parameters ( p1, p2, p3)

My requirement is
1) if the user pass the parameter p1 as "All", then i want all the rows . else match the p1 into column c1 and retrive particular rows only( For ex if the user pass p1 as 1, then output is 1 row only)

2) if the user pass the parameter p2 as "All", then i want all the rows . else match the p2 into column c2 and retrive particular rows only( For ex if the user pass p2 as a, then output is 1 row only)

3) if the user pass the parameter p3 as "All", then i want all the rows . else match the p3 into column c3 and retrive particular rows only( For ex if the user pass p3 as 01-jan-2009, then output is 1 row only)

How to achieve this, without dynamic SQL.
And my stored procedure is

CREATE PROCEDURE TESTP(@P1 CHAR)
AS
BEGIN
SELECT C1, C2, C3 FROM TEST
WHERE
C2 = (CASE WHEN @P1='ALL' THEN C2 ELSE @P1 END)


This procedure take too much time for running.Please guide me to solve this issue.




senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-28 : 09:28:36
Search DEFAULT Argument in BOL

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -