Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to search using stored procedure Expand / Collapse
Author
Message
Posted Friday, September 20, 2013 7:58 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 81, 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)


  Post Attachments 
search.JPG (17 views, 43.29 KB)
Post #1497092
Posted Friday, September 20, 2013 9:02 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 745, Visits: 4,776
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

Post #1497095
Posted Friday, September 20, 2013 9:16 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 81, 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???...
Post #1497097
Posted Friday, September 20, 2013 9:51 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 745, Visits: 4,776
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;

Post #1497102
Posted Friday, September 20, 2013 10:05 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 81, 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
Post #1497103
Posted Monday, September 23, 2013 1:18 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 745, Visits: 4,776
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.
Post #1497514
Posted Monday, September 23, 2013 1:37 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 13,302, Visits: 12,168
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)
Post #1497523
Posted Monday, September 23, 2013 6:56 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 81, 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 ..

Post #1497609
Posted Monday, September 23, 2013 6:57 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 81, 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
Post #1497611
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse