title: Get the error: The correlation name 'General' is specified multiple times in a FROM clause
body: <pre><code>ALTER PROCEDURE [dbo].[REPORTING_MonthlyClientTimesheet_wrapper2_TRR_Month]
        (@StartDate DATETIME,
         @taskcode VARCHAR(250),
         @username VARCHAR(250))
  AS 
  BEGIN 
        SET NOCOUNT ON 
        DECLARE @ProcedureName SYSNAME     
  
          -- Give them one full month of records
        DECLARE @EndDate DATETIME
  
  
        SET @ProcedureName = OBJECT_NAME(@@PROCID) 
  
         --SET @EndDate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@StartDate)+1,0)) -- end month
        SET @EndDate = DATEADD(s, -1, DATEADD(YY, DATEDIFF(YYYY, 0, @StartDate) + 1, 0)) --set to end of Year
  
  
        BEGIN TRY
  
  
              SELECT DISTINCT
                  @username,
                  cal.calendaryear,
                  cal.calendarmonth,
                  cal.calendarday,
                  DATEPART(wk, Calendardate) AS weekno,
                  DATENAME(month, DATEADD(month, cal.calendarmonth - 1, 0)) AS iMonthName,
                  DATEADD(s, -1, DATEADD(YY, DATEDIFF(YYYY, 0, @StartDate) + 1, 0)) AS enddated,
                  LEFT(cal.dayofweekname, 2) AS Weekday,
                      --  Taskcode,
                  CASE WHEN Duration IS NULL THEN 0
                       ELSE duration
                  END AS hours,
                  CASE WHEN leave.leave IS NULL THEN 0
                       ELSE leave.leave
                  END AS leave,
                  CASE WHEN TOIL.toil IS NULL THEN 0
                       ELSE TOIL.toil
                  END AS toil,
                  CASE WHEN sick.sick IS NULL THEN 0
                       ELSE sick.sick
                  END AS sick,
                  CASE WHEN General.General IS NULL THEN 0
                       ELSE General.General
                  END AS General,
                  CONVERT(VARCHAR(10), Calendardate, 103) AS Calendardate
              FROM
                  (SELECT
                      UserInfo.ID AS UserID,
                      dbo.UserInfo.FirstName,
                      tse.Id AS TimesheetentryID,
                      tse.EntryDate,
                      Duration,
                      TaskCode,
                      TaskId,
                      tts.Id AS tasktimesheetid,
                      YEAR(entrydate) AS EntryYear,
                      MONTH(entrydate) AS EntryMOnth,
                      DAY(entrydate) AS Entryday
                   FROM
                      TimesheetEntry tse
                   INNER JOIN TaskTimesheet tts ON tse.TaskTimesheetId = tts.Id
                   INNER JOIN dbo.Task WITH (NOLOCK) ON dbo.task.Id = TTS.TaskId
                   INNER JOIN dbo.ReportPeriod WITH (NOLOCK) ON TTS.ReportPeriodId = dbo.ReportPeriod.Id
                   INNER JOIN dbo.Login WITH (NOLOCK) ON dbo.ReportPeriod.UserId = dbo.Login.UserId
                   INNER JOIN dbo.UserInfo WITH (NOLOCK) ON dbo.ReportPeriod.UserId = dbo.UserInfo.Id
                   INNER JOIN dbo.[Login] logdet WITH (NOLOCK) ON logdet.Userid = UserInfo.Id
                   WHERE
                      Task.TaskCode = @taskcode
                      AND 'a\' + login.LoginName = @username) TimeSE
              RIGHT JOIN dbo.TestCalendar cal ON cal.CalendarYear = Entryyear
                                                 AND cal.CalendarMonth = entrymonth
                                                 AND cal.CalendarDay = entryday
              LEFT JOIN (SELECT --UserInfo.ID as UserID,
                          --  dbo.UserInfo.FirstName,
                          --  tse.Id as TimesheetentryID,
                          tse.EntryDate,
                          Duration AS General
                          --  TaskCode,                           
                          --  TaskId,
                          --  tts.Id as tasktimesheetid,
                          --  year(entrydate) as EntryYear,
                          --  month(entrydate) as EntryMOnth,
                          --  day(entrydate) as Entryday
                         FROM
                          TimesheetEntry tse
                         INNER JOIN TaskTimesheet tts ON tse.TaskTimesheetId = tts.Id
                         INNER JOIN dbo.Task WITH (NOLOCK) ON dbo.task.Id = TTS.TaskId
                         INNER JOIN dbo.ReportPeriod WITH (NOLOCK) ON TTS.ReportPeriodId = dbo.ReportPeriod.Id
                         INNER JOIN dbo.Login WITH (NOLOCK) ON dbo.ReportPeriod.UserId = dbo.Login.UserId
                         INNER JOIN dbo.UserInfo WITH (NOLOCK) ON dbo.ReportPeriod.UserId = dbo.UserInfo.Id
                         INNER JOIN dbo.[Login] logdet WITH (NOLOCK) ON logdet.Userid = UserInfo.Id
                         WHERE
                          Task.TaskCode = @taskcode
                          AND 'a\' + login.LoginName = @username
                          AND TaskCode = 'KPJ.GENERAL') AS General ON general.EntryDate = cal.CalendarDate
              LEFT JOIN (SELECT
                          userid,
                          EntryDate,
                          SUM(Hours) AS leave
                         FROM
                          TimeOffs Toff
                         INNER JOIN TimeOffCode ToffC ON toff.TimeOffCodeId = toffc.Id
                         INNER JOIN dbo.TimeOffEntries ToffE ON toffe.timeoffid = toff.id
                         WHERE
                          name IN ('Bank &amp; Public Holidays', 'Annual Leave', 'authorised Absence')
                          AND EntryDate &gt;= @startdate
                          AND EntryDate &lt;= @enddate
                          AND userid = (SELECT
                                          UserId
                                        FROM
                                          login
                                        WHERE
                                          'a\' + LoginName = @username)
                         GROUP BY
                          toff.UserId,
                          EntryDate) AS Leave ON leave.EntryDate = cal.calendardate
              LEFT JOIN --TOIL
                  (SELECT
                      toff.userid,
                      EntryDate,
                      Hours AS TOIL
                   FROM
                      TimeOffs Toff
                   INNER JOIN TimeOffCode ToffC ON toff.TimeOffCodeId = toffc.Id
                   INNER JOIN dbo.TimeOffEntries ToffE ON toffe.timeoffid = toff.id
                   WHERE
                      name IN ('TOIL')
                      AND EntryDate &gt;= @StartDate
                      AND EntryDate &lt;= @enddate
                      AND userid = (SELECT
                                      UserId
                                    FROM
                                      Login
                                    WHERE
                                      'a\' + LoginName = @username)) AS TOIL ON TOIL.EntryDate = cal.calendardate
              LEFT JOIN --SICK
                  (SELECT
                      toff.userid,
                      EntryDate,
                      Hours AS SICK
                   FROM
                      TimeOffs Toff
                   INNER JOIN TimeOffCode ToffC ON toff.TimeOffCodeId = toffc.Id
                   INNER JOIN dbo.TimeOffEntries ToffE ON toffe.timeoffid = toff.id
                   WHERE
                      name IN ('SICK')
                      AND EntryDate &gt;= @startdate
                      AND EntryDate &lt;= @enddate
                      AND userid = (SELECT
                                      UserId
                                    FROM
                                      login
                                    WHERE
                                      'a\' + LoginName = @username)) AS SICK ON SICK.EntryDate = cal.calendardate
              LEFT JOIN --SICK
                  (SELECT
                      toff.userid,
                      EntryDate,
                      Hours AS SICK
                   FROM
                      TimeOffs Toff
                   INNER JOIN TimeOffCode ToffC ON toff.TimeOffCodeId = toffc.Id
                   INNER JOIN dbo.TimeOffEntries ToffE ON toffe.timeoffid = toff.id
                   WHERE
                      name IN ('SICK')
                      AND EntryDate &gt;= @startdate
                      AND EntryDate &lt;= @enddate
                      AND userid = (SELECT
                                      UserId
                                    FROM
                                      login
                                    WHERE
                                      'a\' + LoginName = @username)) AS General ON SICK.EntryDate = cal.calendardate
              WHERE
                  cal.Calendardate &gt;= @startdate
                  AND Cal.calendardate &lt;= DATEADD(s, -1, DATEADD(YY, DATEDIFF(YYYY, 0, @startdate) + 1, 0))
              ORDER BY
                  cal.CalendarMonth
        END TRY 
        BEGIN CATCH 
              SELECT
                  @ProcedureName AS StoredProcName,
                  ERROR_NUMBER() AS ErrorNumber ; 
  
              RETURN(-1) 
        END CATCH 
  
        RETURN(0) 
  END 
  </code></pre>