Hi! I have two table
People
Id
|
LastName
|
Name
|
Birthday
|
Phone
|
1
|
Mirzoev
|
Amonullo
|
01.01.1989
|
918516168
|
2
|
Mirzoev
|
Bahrullo
|
01.03.1983
|
918555555
|
3
|
Pulodov
|
Rustam
|
22.12.1987
|
918333333
|
4
|
Pulodov
|
Firuz
|
19.04.1998
|
907777475
|
5
|
Soliev
|
Firuzjon
|
16.06.1988
|
918399992
|
TableFruits
Id
|
IdPeople
|
Fruits
|
1
|
2
|
Apple
|
2
|
4
|
Orange
|
3
|
5
|
Cherry
|
I used asp.net form with textbox. I want use search by idpeople from TableFruits. I used below script in sql it’s worked, but I have some problem.
CREATE PROCEDURE GETPEOPLE
@NS VARCHAR(25),
@N VARCHAR(25)
AS
SET @NS=LTRIM(RTRIM(@NS))
SET @N=LTRIM(RTRIM(@N))
IF @NS<>'' AND @N<>''
BEGIN
SELECT LastName, Name, Birthday, Phone FROM People P INNER JOIN TableFruit f ON P.Id = f.id
WHERE LastName=@NS AND Name=@N
END
IF @NS<>'' AND @N=''
BEGIN
SELECT LastName, Name, Birthday, Phone FROM People P INNER JOIN TableFruit f ON P.Id = f.id
WHERE LastName=@NS AND Name=@N
END
IF @NS='' AND @N<>''
BEGIN
SELECT LastName, Name, Birthday, Phone FROM People P INNER JOIN TableFruit f ON P.Id = f.id
WHERE LastName=@NS AND Name=@N
END
When I input Mirzoev it’s found two I want find only one because I have one IdPeople in TableFruit for Mirzoev. Only need find from TableFruit not from People when it’s exist in people and not exist in TableFruit.