hi,
I have a simple stored procedure like so:
ALTER PROCEDURE [dbo].[spList_Report]
@id INT
AS
SET NOCOUNT ON
SELECT *
FROM
tblProducts as products
WHERE
product.intID = @id
I have 2 user tables: MainUser and SubUser Both tables have a foreign key column productID which is related to the primary key intID of the product table intID. They both also have a column emailAddress. The product table also has a bit column isMainUser.
How can I update my stored procedure to return the column emailAddress based on the isMainUser value? So if the value is true it selects the email address from the MainUser table and if its false then it selects the emailAddress from the SubUser table.
E.g what I want is only one emailAddress column:
ALTER PROCEDURE [dbo].[spList_Report]
@id INT
AS
SET NOCOUNT ON
SELECT
products.*
, myUser.emailAddress
FROM
tblProducts as products
WHERE
product.intID = @id