|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Search Stored Procedure
Hi guys,
I'm trying to create a stored procedure to search a database based on a first name. I have come up with the following but it does not seem to be working. Can anyone tell me why? Code:
ALTER PROCEDURE usp_Search
@SearchText nchar(10)
AS
BEGIN
SELECT dbo.Person.PersonID, dbo.Person.FirstName, dbo.Person.LastName, dbo.Person.ExtID, dbo.Person.Mobile, dbo.Position.Position_Name,
dbo.Section.Section_Name, dbo.Division.Division_Name
FROM dbo.Person INNER JOIN
dbo.Extension ON dbo.Person.ExtID = dbo.Extension.ExtID INNER JOIN
dbo.Position ON dbo.Person.PositionID = dbo.Position.Position_ID INNER JOIN
dbo.Section ON dbo.Person.SectionID = dbo.Section.Section_ID INNER JOIN
dbo.Division ON dbo.Section.Division_ID = dbo.Division.Division_ID
WHERE Person.FirstName LIKE '%' + @SearchText + '%'
END
|
|
#2
|
|||
|
|||
|
One thing I noticed is that you are joining to an Extension table but you are not pulling any fields from that table. You may not need to link that table. That may be an issue if you do not have any related records in that table. That goes that same for all the tables you are joining. Make sure you have related records in those tables.
Also, what exactly do you mean by it is not working? Is it just that no records are being returned or a specific error is being returned? |
|
#3
|
|||
|
|||
|
Solved. The parameter needed to be varchar as it was inputting as if it had spaces after it which is why records were coming back weird... so say, if i entered matthew it would come out 'matthew '
Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Search Stored Procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|