Flexible SQL Client Search

Person

| p_id | n_name | l_name | address | city ​​| condition | zip |

Customer

| p_id | reward_points | balance sheet |

Person_PhoneNum

| ppn_id | p_id | number |

The main problem is that I want to try to create a Retrieve stored procedure that can search for any of the Person fields, as well as for the phone number or p_id, but I want it to be able to handle NULL values ​​from the parameters. The following is the stored procedure:

CREATE PROCEDURE RetrieveCust(
@p_id AS varchar(50),
@f_name AS varchar(50),
@l_name AS varchar(50),
@address AS varchar(50),
@city AS varchar(50),
@state AS varchar(50),
@zip AS varchar(50),
@number AS varchar(50))

AS
BEGIN

END

I understand that I need to join tables to match the results, but I don’t know what I could do to handle NULL values. Any help would be awesome!

+3
source share
2 answers

NULL . , :

( @f_name = f_name ) or ( @f_name is null )

, .

, , , , , DISTINCT p_id.

? , .

+2

-

where (f_name = @f_name or @f_name is null)
+1

Source: https://habr.com/ru/post/1771408/


All Articles