Items Table:
id | item_name | code | cust_id |
---|---|---|---|
1 | Mango | 111 | u1 |
2 | Milk | 112 | u2 |
3 | Chocolate | 113 | u3 |
4 | Milk | 112 | u1 |
5 | Mango | 111 | u2 |
6 | Berry | 114 | u3 |
7 | Chocolate | 113 | u1 |
8 | Berry | 114 | u2 |
9 | Ice-cream | 114 | u3 |
10 | Mango | 111 | u4 |
These is the customer table and I have to write an stored procedure in SQL Server to find the cust_id who have buy all items passed in comma separated values like 'Mango,Milk,Chocolate'
CREATE PROCEDURE Items_find
@items_value nvarchar(max)
AS
BEGIN
END
EXEC Items_find 'Mango,Milk,Chocolate'
EXEC Items_find 'Mango,Milk'
Stored procedure should return cust_id = u1
if 'Mango,Milk'
then output should be cust_id=u1, u2
or if 'Mango'
then output is cust_id=u1, u2, u3
I have tried to filter out the cust_id
w.r.t. to the count of items passed in comma-separated but after that I am not able find the cust_id
who buys specifically these items