Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics SL (Archived)

Using PV Case Statements Does Not supported in StoreProcedure

Posted on by 555

I have create a new Pv in Intran.User1 field in Recipts Screen.
Have altered Site_With_InvtFlag Procedure ,Have a custom Table X_site in X_Site Columns are UserID,SiteId and Enable .

Intran.USer1 PV:"X_Site_With_InvtFlag", "bpes.cpnyid"; 0; 0; 0; 0, "bintran.invtid"; 0; 0; 0; 0, "bPes.UserId"; 0; 0; 0; 0,

CustomPv.Csv: X_Site_With_InvtFlag,,,SELECT * FROM vi_SiteWithInvtFlag WHERE CpnyID = @Parm1 AND (InvtID = @Parm2 or (InvtID is null and not exists (select 'x' from vi_SiteWithInvtFlag v2 where vi_SiteWithInvtFlag.CpnyID = v2.CpnyID AND v2.InvtID = @Parm2 AND vi_SiteWithInvtFlag.SiteID = v2.SiteID ))) And siteid =(CASE WHEN @Parm3 not in (select Top 1 UserId from X_site x where x.UserId=@Parm3) then SiteId WHEN vi_SiteWithInvtFlag.User5=0 then SiteId when vi_SiteWithInvtFlag.User5=1 AND vi_SiteWithInvtFlag.SiteId is not null and (not exists (select 'x' from X_site x where vi_SiteWithInvtFlag.SiteId=x.SiteId and not (x.UserId = @Parm3 and enable =1 ))or exists(select 'x' from X_site x where vi_SiteWithInvtFlag.SiteId=x.SiteId and (x.UserId = @Parm3 and enable=1))) Then siteid end) AND vi_SiteWithInvtFlag.SiteId LIKE @Parm4 ORDER BY vi_SiteWithInvtFlag.SiteID,Site,vi_SiteWithInvtFlag.SiteID;Site ID;118;0,vi_SiteWithInvtFlag.Name;Name;110;0,vi_SiteWithInvtFlag.ExistingSiteFlag;Active Site for this Item;0;0

 if Site.User5=1 then it's restricted site and if the particular user have access in X_Site then only he can see the site.

X_site Table Sample:

UserId SiteId Enable
SYSADMIN 200 1
USerA 400 1
Thillai 200 1
ANBURAJ 200 1

My StoreProcedure is

In procedure have  passing CurrentUserID as @Param3

Create PROCEDURE X_Site_With_InvtFlag
@Parm1 VARCHAR (10),--'0060' CpnyID
@Parm2 VARCHAR (30),--'0RBOLT' InvtID
@Parm3 VARCHAR (30),--'SYSADMIN' --Here have changed Invt Id to USerID
@Parm4 VARCHAR (10)--% --SiteID
As

SELECT distinct * FROM vi_SiteWithInvtFlag WHERE CpnyID = @Parm1 AND (InvtID = @Parm2 or (InvtID is null and not exists
(select 'x' from vi_SiteWithInvtFlag v2 where vi_SiteWithInvtFlag.CpnyID = v2.CpnyID AND v2.InvtID = @Parm2 AND vi_SiteWithInvtFlag.SiteID
= v2.SiteID ))) And siteid = ( CASE WHEN @Parm3 not in (select Top 1 UserId from X_site x where x.UserId=@Parm3) then SiteId WHEN
vi_SiteWithInvtFlag.User5=0 then SiteId when vi_SiteWithInvtFlag.User5=1 AND vi_SiteWithInvtFlag.SiteId is not null and (not exists
(select 'x' from X_site x where vi_SiteWithInvtFlag.SiteId=x.SiteId and not (x.UserId = @Parm3 and enable =1 ))or exists(select 'x' from X_site
x where vi_SiteWithInvtFlag.SiteId=x.SiteId and (x.UserId = @Parm3 and enable=1))) Then siteid end) AND vi_SiteWithInvtFlag.SiteId
LIKE @Parm4 ORDER BY vi_SiteWithInvtFlag.SiteID

The above sp is Perfectly working in Sql .but in Screen i press f3 then error only showing .Have attached the First error screen shot and 2 nd error is The cursor (82) has 0 columns associated it should be greater then o and less then or equal to 256 .

Here UserID as @Param3 but in Error screen showing X.userid='0060' so it collaspe the Params.but have removed the case statement in Store procedure then it will works fine.but very difficult to write without case statements.

Please any one help me.

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans