I would like to know how do I select a parameter based on the result set from a stored procedure.
My code looks something like this:
CREATE PROCEDURE usp_UserInformation (@ReportRunDate DATE = NULL)
AS
WITH CTE AS (
SELECT -- some fields
FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID
WHERE RegisteredDate = DATEADD(MONTH, DATEDIFF(MONTH, -1, @ReportRunDate) - 2, -1)
--I'll output the result set after applying all the logic like
SELECT UserID, UserName, DOJ
FROM CTE
Now, when the user selects the date on the report, I created another parameter and trying to retrieve records from the "Available Values" using 'Get values from a query'. I would like to show the list of UserIDs from the above query result set and allow the user SELECT based on that.
UPDATE: I have created another stored procedure as there is no other alternative. Now my question is, how do I pass the second stored procedure value to the first one in WHERE clause?
CREATE PROCEDURE usp_UserInformation (@ReportRunDate DATE = NULL)
AS
WITH CTE AS (
SELECT -- some fields
FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID
WHERE RegisteredDate = DATEADD(MONTH, DATEDIFF(MONTH, -1, @ReportRunDate) - 2, -1)
--I'll output the result set after applying all the logic like
SELECT User_ID, UserName, DOJ
FROM CTE
WHERE User_ID = EXEC usp_Get_UserID
I am looking for something like this where the user can select the ID first and any date of his choice in the report.
PS: I am not allowed to write in-line SQL and only SPs are allowed. I don't want to create two SPs for the same report.