September 20, 2013 at 7:58 pm
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)
September 20, 2013 at 9:02 pm
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
September 20, 2013 at 9:16 pm
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???...
September 20, 2013 at 9:51 pm
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;
September 20, 2013 at 10:05 pm
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 🙂
September 23, 2013 at 1:18 pm
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.
September 23, 2013 at 1:37 pm
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/[/url]
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 23, 2013 at 6:56 pm
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/[/url]
Thanks sean,,,you are always the champion!!!
I Got it :-)..
September 23, 2013 at 6:57 pm
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 🙂
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply