SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 4th, 2004, 04:35 AM
Jessy George Jessy George is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 Jessy George User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Optional parameters in stored procedure

Hi,
I have created a stored proc with optional parameter as

CREATE PROCEDURE SelectFromEmp_Test
@EmpNo int = '%', @EmpName char(15) ='%', @DateOfBirth datetime = '%', @Salary int = '%'
AS
select EmpNumber,EmpName,DateOfBirth,Salary from EmpMaster where
EmpNumber Like @EmpNo And EmpName Like @EmpName And
DateOfBirth Like @DateOfBirth And Salary Like @Salary
GO

Now if I execute it on query analyaser as
execute selectfromEmp_test 1000,'Name','6/17/1982',15000

then it runs but if i want to use some wildcard character, how to use them?
and how to pass only 1st and 3rd parameter?

Reply With Quote
  #2  
Old June 4th, 2004, 09:24 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Example:
This will work if you allow NULL values in the fields.
Code:
CREATE PROCEDURE TestProc 
( 
@Param1 varchar(50) = NULL, 
@Param2 varchar(50) = NULL, 
@Param3 varchar(50) = NULL 
) 
AS 
SELECT * 
FROM 
TestTable 
WHERE col1 = ISNull( @Param1,col1 ) 
AND col2 = ISNull( @Param2,col2 ) 
AND col3 = ISNull( @Param3,col3 ) 

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Optional parameters in stored procedure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT