Stored Proc Reverse Engineering issue
See original GitHub issueI am getting the below error message when reverse engineering the stored procedure. I have several procedures with similar pattern, but only this one is throwing error, rest are successfully reverse engineered.
Unable to get result set shape for PROCEDURE 'dbo.sp_GetOrgLocationCategoriesWithStates'
The metadata could not be determined because the statement 'SELECT CAST(NULL as uniqueidentifier) OrgLocationCategoryID_PK, CAST(NULL as uniqueidentifier) OrgLo' in procedure 'sp_GetOrgLocationCategoriesWithStates' is not compatible with the statement 'SELECT OLC.[OrgLocationCategoryID_PK],OLC.[OrgLocationID_FK],OLC.[CategoryName],OLC.[CategoryCode],[' in procedure 'sp_GetOrgLocationCategoriesWithStates'.
Using Visual Studio 2022 Version 17.1.0 Preview 1.1 EF Core Power Tools for visual studio version 2.5.832.0
CREATE PROCEDURE [dbo].[sp_GetOrgLocationCategoriesWithStates]
(
@OrgLocationID uniqueidentifier,
@OrgLocationTerminalID uniqueidentifier,
@userID_FK uniqueidentifier,
@ErrorMessage varchar(500) OUTPUT
)
AS
BEGIN
BEGIN TRY
DECLARE @MessageID varchar(50);
SET @ErrorMessage='';
IF(@userID_FK IS NULL OR LTRIM(RTRIM(@userID_FK)) ='' OR @userID_FK ='00000000-0000-0000-0000-000000000000')
BEGIN
SET @ErrorMessage='Required Parameter userID_FK was not supplied'
Return 0
END
DECLARE @FoundOrgLocationID uniqueidentifier = NULL;
DECLARE @OrgID uniqueidentifier = NULL;
IF(@OrgLocationID IS NULL OR LTRIM(RTRIM(@OrgLocationID)) = '' OR @OrgLocationID = '00000000-0000-0000-0000-000000000000')
BEGIN
IF(@OrgLocationTerminalID IS NULL OR LTRIM(RTRIM(@OrgLocationTerminalID)) = '' OR @OrgLocationTerminalID = '00000000-0000-0000-0000-000000000000')
BEGIN
SET @ErrorMessage='Either OrgLocationID or OrgLocationTerminalID is Required'
Return 0
END
ELSE
BEGIN
SELECT @FoundOrgLocationID=OL.[Org_LocationID_PK], @OrgID=OL.[OrgID_FK] FROM [dbo].[Org_Location_Terminal] OLT
INNER JOIN [dbo].[Org_Location] OL ON OL.[Org_LocationID_PK]=OLT.OrgLocationID_FK
WHERE OLT.[OrgLocationTerminalID_PK] = @OrgLocationTerminalID
IF(@FoundOrgLocationID IS NULL)
BEGIN
SET @ErrorMessage='Invalid OrgLocationTerminalID';
Return 0
END
ELSE
SET @OrgLocationID = @FoundOrgLocationID;
END
END
ELSE
BEGIN
Select @FoundOrgLocationID=[Org_LocationID_PK],@OrgID=OL.[OrgID_FK] from [dbo].[Org_Location] OL
WHERE [Org_LocationID_PK] =@OrgLocationID
END
IF(@FoundOrgLocationID IS NULL)
BEGIN
SET @ErrorMessage='Invalid OrgLocationID';
Return 0
END
PRINT 'STORED Procedure Called'
DECLARE @UserIDFound uniqueidentifier = NULL;
DECLARE @UserOrgID uniqueidentifier = NULL;
DECLARE @IsOrgAdmin bit=0;
Select @UserIDFound =[UserID_FK],@UserOrgID=[OrgID_FK] from [dbo].[Org_Users] where [UserID_FK]=@UserID_FK
IF(@UserIDFound IS NOT NULL)
BEGIN
If(@OrgID <> @UserOrgID)
BEGIN
SET @ErrorMessage='Not Authorized, Users OrgID(' + cast(@UserOrgID as varchar(36)) + ') does not match with OrgLocationCategory OrgID ' + cast(@OrgID as varchar(36));
Return 0
END
END
ELSE
BEGIN
--Search if User is Location Admin
Select @UserIDFound =[UserID_FK],@UserOrgID=OL.[OrgID_FK] from [dbo].[Org_Location_User] OLU
INNER JOIN [dbo].[Org_Location] OL ON OL.[Org_LocationID_PK] = OLU.[OrgLocationID_FK]
INNER JOIN [dbo].[RoleTypes] RT ON RT.[RoleTypeID_PK] = OLU.[RoleTypeID_FK]
Where OLU.[UserID_FK]=@UserID_FK AND (RT.[RoleName]='LocationAdmin' OR RT.[RoleName]='LocationOperator')
IF(@UserIDFound IS NULL)
BEGIN
SET @ErrorMessage='Not Authorized, User Not Found';
Return 0
END
ELSE
BEGIN
If(@OrgID <> @UserOrgID)
BEGIN
SET @ErrorMessage='Not Authorized, Users OrgID(' + cast(@UserOrgID as varchar(36)) + ') does not match with OrgLcoationCategory OrgID ' + cast(@OrgID as varchar(36));
Return 0;
END
END
END
PRINT 'EXECUTING SELECT'
SELECT OLC.[OrgLocationCategoryID_PK],OLC.[OrgLocationID_FK],OLC.[CategoryName],OLC.[CategoryCode],[OrgLoctionCategoryStateID_PK],[StateName],[StateDescription],[SequenceNumber]
FROM [dbo].[Org_Location_Category] OLC
LEFT JOIN [dbo].[Org_Location_Category_State] OLCS ON OLCS.OrgLocationCategoryID_FK = OLC.OrgLocationCategoryID_PK and OLCS.StateName <> 'ALL'
WHERE [OrgLocationID_FK] = @OrgLocationID AND (OLCS.IsActive IS NULL OR OLCS.IsActive=1) AND OLC.IsActive=1;
RETURN 1;
END TRY
BEGIN CATCH
SET @ErrorMessage='Try Catch Error Occured ' + ERROR_MESSAGE();
SELECT CAST(NULL as uniqueidentifier) OrgLocationCategoryID_PK, CAST(NULL as uniqueidentifier) OrgLocationID_FK, CAST(NULL as varchar(500)) CategoryName, CAST(NULL as varchar(10)) CategoryCode,
CAST(NULL as uniqueidentifier) OrgLoctionCategoryStateID_PK, CAST(NULL as varchar(500)) StateName, CAST(NULL as varchar(500)) StateDescription, CAST(NULL as int) SequenceNumber;
Return 0;
END CATCH
END
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
database - Stored procedures reverse engineering
I wrote a recursive query using CTE to achieve this. The single best tool for reverse engineering is by APEX. Its amazing.
Read more >Reverse Engineering with Stored Procedures
When you reverse engineer a model that contains stored procedures, all the stored procedures move to the model-level. To maintain any table-level stored ......
Read more >Reverse Engineer Wizard: Select stored procedures
Choose the stored procedures that you want the wizard to reverse engineer. ... Displays all the stored procedures that you can extract from...
Read more >Reverse engineer stored procedure no generate EntityResult
When I use Reverse Engineering, I expected the tool creates an entity with the columns in the selects, but I doesn´t. The tool...
Read more >Database Reverse Engineering
The article describes database reverse engineering, its main elements, and examples of how to obtain various types of information for DB ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found it, i had to use nvarchar in the last result because my top query is returning data type of nvarchar.
Output from sp_describe_first_result_set was helpful in finding the discrepancy.
As I said, test with sp_describe_first_result_set