Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to search using stored procedure


How to search using stored procedure

Author
Message
enriquezreyjoseph
enriquezreyjoseph
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 191
Hello Word and Hello all pipz

Good Day!!!


I need some advice on how to search using stored procedure...

I have 3 tables namely Bio, Sex and Status

*Bio
bioID
firstname
middlename
lastname
sexID
statusID

*Sex
sexID
sex(male or female only)

*Status
statusID
status(Single, Married or devorce only)


I want to search Firstname, Middlename, Lastname, sex and status.

what should i do?...

thanks hoping for a reply :-)

this is my UI (Please see my attachment, please be guided accordingly..thanks)
Attachments
search.JPG (17 views, 43.00 KB)
pietlinden
pietlinden
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2171 Visits: 12480
Are the pick lists for 3 possible values really necessary? Simplify, then you're done.

You could do this...

SELECT bioID
   , FirstName
   , LastName
   , Sex
   , Status
FROM Bio INNER JOIN Sex ON Bio.SexID=Sex.SexID
INNER JOIN [Status]
ON Bio.StatusID=Status.StatusID
WHERE FirstName = @FirstName
AND LastName = @LastName



But picklists for 3 possible values are kind of overkill, I think. You can just as easily use a CHECK constraint, and a single character (M,D,S...) M/F
enriquezreyjoseph
enriquezreyjoseph
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 191
pietlinden (9/20/2013)
Are the pick lists for 3 possible values really necessary? Simplify, then you're done.

You could do this...

SELECT bioID
   , FirstName
   , LastName
   , Sex
   , Status
FROM Bio INNER JOIN Sex ON Bio.SexID=Sex.SexID
INNER JOIN [Status]
ON Bio.StatusID=Status.StatusID
WHERE FirstName = @FirstName
AND LastName = @LastName



But picklists for 3 possible values are kind of overkill, I think. You can just as easily use a CHECK constraint, and a single character (M,D,S...) M/F



Hi,

i Think you are creating a View, am i right???...
pietlinden
pietlinden
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2171 Visits: 12480
No. I was leaving out a bunch of stuff. It was the bare bones of a stored procedure. One of the differences between a view and a stored procedure is that you cannot pass parameters to a view, but you can to a stored procedure.

For example
CREATE VIEW vw_allFemales AS 
SELECT FirstName, LastName
FROM Person
WHERE Gender = 'F';



Stored procedure:
CREATE PROC usp_EmployeesByGender
@Gender CHAR
AS
SELECT FirstName, LastName
FROM Person
WHERE Gender = @Gender;


enriquezreyjoseph
enriquezreyjoseph
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 191
pietlinden (9/20/2013)
No. I was leaving out a bunch of stuff. It was the bare bones of a stored procedure. One of the differences between a view and a stored procedure is that you cannot pass parameters to a view, but you can to a stored procedure.

For example
CREATE VIEW vw_allFemales AS 
SELECT FirstName, LastName
FROM Person
WHERE Gender = 'F';



Stored procedure:
CREATE PROC usp_EmployeesByGender
@Gender CHAR
AS
SELECT FirstName, LastName
FROM Person
WHERE Gender = @Gender;



Thank you my Friend :-)

so meaning, i can use the code that you leave to me in my search using stored procedure??..

here hoping :-)
pietlinden
pietlinden
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2171 Visits: 12480
I think you can use it. The best way to find out is to use a "sandbox" database (or something you can mess up and it won't matter), and TRY it.

When I was where you are (not that long ago, actually), I just tried a bunch of things to see how SQL Server was like/unlike other database software I had used before. Sounds simplistic, but the best way to learn is to get your hands dirty. Definitely a good reason to download the MSI for one of the Microsoft canned databases. You can examine, use and abuse the thing and then when it breaks either fix it (if you're good enough), or just restore from the backup. -- which is a great skill to have anyway.

If you have never gotten into that, Grant Fritchey has a great video on YouTube where he walks you through the whole thing.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16527 Visits: 16992
Based on your screen shot and the description this sounds like a search criteria based on the values the user wants to use as their criteria. This is a very common problem. Gail's article is far and above the best read and approach to this type of query you will find anywhere. Read her article and post back here if you need some help implementing this.

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
enriquezreyjoseph
enriquezreyjoseph
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 191
Sean Lange (9/23/2013)
Based on your screen shot and the description this sounds like a search criteria based on the values the user wants to use as their criteria. This is a very common problem. Gail's article is far and above the best read and approach to this type of query you will find anywhere. Read her article and post back here if you need some help implementing this.

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/




Thanks sean,,,you are always the champion!!!

I Got it :-)..
enriquezreyjoseph
enriquezreyjoseph
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 191
pietlinden (9/23/2013)
I think you can use it. The best way to find out is to use a "sandbox" database (or something you can mess up and it won't matter), and TRY it.

When I was where you are (not that long ago, actually), I just tried a bunch of things to see how SQL Server was like/unlike other database software I had used before. Sounds simplistic, but the best way to learn is to get your hands dirty. Definitely a good reason to download the MSI for one of the Microsoft canned databases. You can examine, use and abuse the thing and then when it breaks either fix it (if you're good enough), or just restore from the backup. -- which is a great skill to have anyway.

If you have never gotten into that, Grant Fritchey has a great video on YouTube where he walks you through the whole thing.


Thanks my Friend :-)..

Cheers :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search