Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getUserCartItem]
(
@PID int,
@UserID int
)
AS
SELECT * FROM tblProducts WHERE PID=@PID 
SELECT * FROM tblCart WHERE PID = @PID AND UID = @UserID


What I have tried:

<pre>SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getUserCartItem]
(
@PID int,
@UserID int
)
AS
(SELECT * FROM tblProducts WHERE PID=@PID) 
(SELECT * FROM tblCart WHERE PID = @PID AND UID = @UserID)
Posted
Updated 27-May-21 22:15pm
v2
Comments
Sandeep Mewara 28-May-21 4:15am    
What is your SP expected to return?
Member 15100384 28-May-21 4:45am    
PQuantity from tblProducts
Qty from tblCart

1 solution

Your code as shown executes without problem - it may or may not execute when you try to run the query, but since we have no access to your DB we can't test that.
I'd add a BEGIN and END though:
SQL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getUserCartItem]
(
@PID int,
@UserID int
)
AS
BEGIN
   SELECT * FROM tblProducts WHERE PID=@PID 
   SELECT * FROM tblCart WHERE PID = @PID AND UID = @UserID
END

That code will return two data sets - one for each SELECT.
In order to combine them and return a single dataset, you would need to look at the database design, the relationships between the two tables, and exactly what you wanted to return before you even started coding SQL!

We can't do any of that for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900