-2
    ALTER PROCEDURE Dashbord @userid INT 
AS 
  BEGIN 
      DECLARE @reportmanager INT 
      DECLARE @admintype INT 

      SET @reportmanager = (SELECT Count(managerid) 
                            FROM   reportingperson 
                            WHERE  employeeid = @userid) 
      SET @admintype = (SELECT Max(admintype) 
                        FROM   employee 
                        WHERE  content_id = @userid) 

      IF EXISTS (SELECT 1 
                 WHERE  @reportmanager > 0 
                        AND @admintype = 0) 
        BEGIN 
            SELECT b.contentid, 
                   x.content_id, 
                   x.employeename, 
                   x.imagetype, 
                   CONVERT(VARCHAR(10), b.fromdate, 126)    AS fromdate, 
                   CONVERT(VARCHAR(10), b.todate, 126)      AS Todate, 
                   b.leaveapp, 
                   b.leavesubject, 
                   b.reason, 
                   ( CASE 
                       WHEN ( b.status = 0 ) THEN 'Pending' 
                       ELSE 'Approved' 
                     END )                                  AS status, 
                   CONVERT(VARCHAR(10), b.createddate, 126) AS Createddate 
            FROM   leaves b 
                   LEFT OUTER JOIN employee x 
                                ON b.employeeid = x.content_id 
            WHERE  ( b.employeeid = @userid ) 
                   AND b.status = 0 

            SELECT admintype 
            FROM   employee 
            WHERE  content_id = @userid 
        END 
      ELSE 
        BEGIN 
            SELECT b.contentid, 
                   x.content_id, 
                   x.employeename, 
                   x.imagetype, 
                   CONVERT(VARCHAR(10), b.fromdate, 126)    AS fromdate, 
                   CONVERT(VARCHAR(10), b.todate, 126)      AS Todate, 
                   b.leaveapp, 
                   b.leavesubject, 
                   b.reason, 
                   ( CASE 
                       WHEN ( b.status = 0 ) THEN 'Pending' 
                       ELSE 'Approved' 
                     END )                                  AS status, 
                   CONVERT(VARCHAR(10), b.createddate, 126) AS Createddate 
            FROM   leaves b 
                   LEFT OUTER JOIN employee x 
                                ON b.employeeid = x.content_id 
            WHERE  b.employeeid IN (SELECT employeeid 
                                    FROM   reportingperson 
                                    WHERE  managerid = @userid) 
                   AND b.status = 0 

            SELECT admintype 
            FROM   employee 
            WHERE  content_id = @userid 
        END 
  END 

その人が休暇を承認したら、通知を別の報告者に送ってから休暇を承認し、従業員がこの家に行くことができるようにしなければなりません

4

1 に答える 1

0

各クエリとサブクエリを取得し、問題の原因となっているクエリを検出するまで単独でテストすることをお勧めします

また、クエリのこの部分では...

left outer join employee x on b.employeeid=x.content_id
where (b.employeeid=@userid 
) and b.status=0

結合を行っている場合、on b.employeeid=x.content_idなぜ WHERE を追加するのですか?b.employeeid=@userid両方の条件が同じフィールドに対してチェックしているため、b.employeeid予期しない動作が発生する可能性があります

于 2013-09-17T14:57:18.027 に答える