Skip to main content
Nintex Community Menu Bar
Solved

Using Stored Procedure for List View - Creating duplicate properties

  • November 7, 2017
  • 4 replies
  • 12 views
  • Translate

Forum|alt.badge.img+8

Although I've used stored procedures for execute commands against the database, this is the first time I'm using one for a list method.  

 

Basically, I want it to query the data slightly based on whether or not they're searching for completed records (<> 1) or incomple records (=1).  

 

When I try to create the Smart Object, however, it gives me two sets of properties UnitID, GroupID, UnitID(1), GroupID(1).  That doesn't work...

 

Anyway, my SPROC is as follows.  Anyone have any thoughts?

 

Rob

 

 

 

 

ALTER PROCEDURE [dbo].[Group_aggregated_sproc_2]

@Searchtype int

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here


if @searchtype = 1 begin

select UnitID, GroupID from recon_work_items
where (currentstatus = 1 or currentstatus > 20)
group by UnitID, GroupID

end

 

else

if @searchtype <> 1
begin
select UnitID, GroupID from recon_work_items
where currentstatus between 2 and 20
group by UnitID, GroupID


END
end

Best answer by VJay

Hi Robert,

 

As there are 2 select statement in the stored procedure you are seeing two columns for each single column of table while creating a SMO.

 

Modify the Stored procedure to make dynamic query which means prepare the Query Statatement based on the conditions and execute the Query Statement at the end.

 

example:

 

Procedure:

Declare @Query NVARCHAR(Max)

If @searchtype = 1

Begin

   Set @Query = 'select UnitID, GroupID from recon_work_items where (currentstatus = 1 or currentstatus > 20) group by UnitID, GroupID'

End

else

if @searchtype <> 1
Begin
  Set @Query = select UnitID, GroupID from recon_work_items where currentstatus between 2 and 20 group by UnitID, GroupID

End

EXECUTE sp_executesql @Query

 

Check this link for the dynamic query

https://www.codeproject.com/Articles/20815/Building-Dynamic-SQL-In-a-Stored-Procedure

 

Regards,

Vijay.

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+9
  • Apprentice
  • 105 replies
  • Answer
  • November 7, 2017

Hi Robert,

 

As there are 2 select statement in the stored procedure you are seeing two columns for each single column of table while creating a SMO.

 

Modify the Stored procedure to make dynamic query which means prepare the Query Statatement based on the conditions and execute the Query Statement at the end.

 

example:

 

Procedure:

Declare @Query NVARCHAR(Max)

If @searchtype = 1

Begin

   Set @Query = 'select UnitID, GroupID from recon_work_items where (currentstatus = 1 or currentstatus > 20) group by UnitID, GroupID'

End

else

if @searchtype <> 1
Begin
  Set @Query = select UnitID, GroupID from recon_work_items where currentstatus between 2 and 20 group by UnitID, GroupID

End

EXECUTE sp_executesql @Query

 

Check this link for the dynamic query

https://www.codeproject.com/Articles/20815/Building-Dynamic-SQL-In-a-Stored-Procedure

 

Regards,

Vijay.

Translate

Forum|alt.badge.img+8

Ahhhh.  Makes perfect sense!  I will try this!

 

Rob

 

 

Translate

Forum|alt.badge.img+9
  • Apprentice
  • 105 replies
  • November 8, 2017

Yeah!!

 

Let me know if it works!!!

 

VJay

Translate

Forum|alt.badge.img+8

It did work!

 

Rob

 

 

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings