[英]Why doesn't my query work for a specific parameter?
I have 3 tables 我有3张桌子
1 is used to register website users. 1用于注册网站用户。 2 is for saving complaints
2用于保存投诉
I will discuss 3 later. 稍后我将讨论3 。
When a complaint is received, it is assigned to a system user ie AssignToUser_ID in complaints table. 收到投诉后,会将其分配给系统用户,即投诉表中的AssignToUser_ID。
Complaints: 投诉:
Now if a user wants to view complaints then only those complaints should be shown which were assigned to a him not other and that is the part I have solved but.... 现在,如果用户要查看投诉,则仅应显示那些分配给他的投诉,而不是其他投诉,这是我已解决但....
Now I will discuss MAPPING table. 现在,我将讨论映射表。
Mapping: 制图:
This table is used to store nominated systemusers ie if a complained was assigned to me and I decide to assign it to another user too so he also can view the complaints that were actually assigned to me then it would be possible. 该表用于存储指定的系统用户,即,如果将投诉分配给我,而我决定也将其分配给另一个用户,那么他也可以查看实际分配给我的投诉,则有可能。 Now this part I have solved somehow but the problem is that If I login as a nominated user then I can view the complaints that were assigned to actual user but if I login as an original user then I can not view the assigned complaints.
现在,我已经以某种方式解决了这一部分,但是问题是,如果我以指定用户身份登录,那么我可以查看分配给实际用户的投诉,但是如果我以原始用户身份登录,则无法查看分配的投诉。
My try: 我的尝试:
CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(
@SystemUser_ID int
)
AS
Begin
if exists (Select * from mapping where systemuser_id = @SystemUser_ID )
begin
Select * From dbo.Complaints Comp
Where (Comp.AssignToUser_ID IN (select assigntouser_id from mapping where systemuser_id = @SystemUser_ID)) AND
Comp.ComplaintStatus_ID <3
end
else
begin
Select * From dbo.Complaints Comp
Where (Comp.AssignToUser_ID = @SystemUser_ID) AND
Comp.ComplaintStatus_ID <3
end
End
You use @SystemUser_ID as a systemuser_id AND as a AssignToUser_ID. 您将@SystemUser_ID用作systemuser_id,并用作AssignToUser_ID。 I think that they are two different notions with their own increments system.
我认为它们是两个具有各自增量系统的不同概念。 Your AssignToUser_ID n°1 is probably not the same as your systemuser_id n°1.
您的AssignToUser_ID n°1可能与systemuser_id n°1不同。
You need to make two different entries depending on your user type (assigned OR system). 您需要根据用户类型(分配的OR系统)进行两个不同的输入。
One way to go: 一种方法:
CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(
@user_ID int,
@user_type char(3)
)
AS
Begin
if @user_type = 'SYS'
begin
Select * From dbo.Complaints Comp
Where Comp.AssignToUser_ID IN (select assigntouser_id
from mapping
where systemuser_id = @user_ID)
AND Comp.ComplaintStatus_ID <3
end
if @user_type = 'ASG'
begin
Select * From dbo.Complaints Comp
Where Comp.AssignToUser_ID = @user_ID
AND Comp.ComplaintStatus_ID <3
end
End
Another way to go would be to make two different stored procedure. 另一种方法是制作两个不同的存储过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.