Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:43:29+00:00 2026-06-05T06:43:29+00:00

I have a problem with this query: SELECT RTRIM(LTRIM(L_MAILITMS.MAILITM_FID)) AS Ref30 , IsNull (Ref33,0)

  • 0

I have a problem with this query:

SELECT     RTRIM(LTRIM(L_MAILITMS.MAILITM_FID)) AS Ref30
         , IsNull (Ref33,0) as Ref33
FROM       L_MAILITM_EVENTS 
   INNER JOIN L_MAILITMS ON L_MAILITM_EVENTS.MAILITM_PID = L_MAILITMS.MAILITM_PID 
WHERE  (L_MAILITMS.MAIL_CLASS_CD = 'E') 
   AND (L_MAILITM_EVENTS.EVENT_OFFICE_CD = 1063) 
   AND (L_MAILITM_EVENTS.EVENT_TYPE_CD = 30) 
   AND (L_MAILITM_EVENTS.EVENT_GMT_DT >= CONVERT(DATETIME, '2012-05-27 00:00:00', 102)) 
   AND (L_MAILITM_EVENTS.EVENT_GMT_DT < CONVERT(DATETIME, '2012-05-28 00:00:00', 102))
LEFT OUTER JOIN 
  (
    SELECT   RTRIM(LTRIM(L_MAILITMS_1.MAILITM_FID)) as Ref3033
           , COUNT(*) as Ref33
    FROM     L_MAILITM_EVENTS as L_MAILITM_EVENTS_1 
       INNER JOIN  L_MAILITMS as L_MAILITMS_1 ON L_MAILITM_EVENTS_1.MAILITM_PID = L_MAILITMS_1.MAILITM_PID
    WHERE  (L_MAILITMS_1.MAIL_CLASS_CD = 'E') 
       AND (L_MAILITM_EVENTS_1.EVENT_OFFICE_CD = 1063) 
       AND (L_MAILITM_EVENTS_1.EVENT_TYPE_CD = 33) 
       AND (L_MAILITM_EVENTS_1.EVENT_GMT_DT >= CONVERT(DATETIME, '2012-05-27 00:00:00', 102))
    GROUP BY L_MAILITMS_1.MAILITM_FID
  )  ON L_MAILITMS.MAILITM_FID = L_MAILITMS_1.MAILITM_FID

an error is generated

Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword ‘LEFT’.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword ‘ON’.

Table L_MAILITMS_EVENTS:

MAILITM_PID     EVENT_OFFICE_CD    EVENT_TYPE_CD
-----------------------------------------------------------
1               1063               30
2               1063               30
2               1063               33
3               1063               33
3               1063               30
4               1063               30

Table L_MAILITMS:

MAILITM_PID          MAILITM_FID        MAIL_CLASS_CD
-------------------------------------------------------
1                     123               E  
2                     452               E                
3                     369               E
4                     633               E

What i want to get:

Ref30          Ref33
-----------------------
123            0
452            1
369            1
633            0

UPDATE : Thanks Sebas for your help

*is there another way for this query to assure speed performance, because i treat about 2500 MAILITM_FID ?*

Can anyone help?
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:43:30+00:00Added an answer on June 5, 2026 at 6:43 am

    Then let me modify the placement of the joins:

        SELECT     RTRIM(LTRIM(m.MAILITM_FID)) AS Ref30
             , IsNull (Ref33,0) as Ref33
    FROM       L_MAILITM_EVENTS me
       INNER JOIN L_MAILITMS m ON me.MAILITM_PID = m.MAILITM_PID
       LEFT OUTER JOIN (
                SELECT   RTRIM(LTRIM(m1.MAILITM_FID)) as Ref3033
                       , COUNT(*) as Ref33
                FROM     L_MAILITM_EVENTS me1
                            INNER JOIN L_MAILITMS m1 ON me1.MAILITM_PID = m1.MAILITM_PID
                WHERE  (m1.MAIL_CLASS_CD = 'E') 
                   AND (me1.EVENT_OFFICE_CD = 1063) 
                   AND (me1.EVENT_TYPE_CD = 33) 
                   AND (me1.EVENT_GMT_DT >= CONVERT(DATETIME, '2012-05-27 00:00:00', 102))
                GROUP BY m1.MAILITM_FID
      ) oj ON m.MAILITM_FID = oj.Ref3033 
    WHERE  (m.MAIL_CLASS_CD = 'E') 
       AND (me.EVENT_OFFICE_CD = 1063) 
       AND (me.EVENT_TYPE_CD = 30) 
       AND (me.EVENT_GMT_DT >= CONVERT(DATETIME, '2012-05-27 00:00:00', 102)) 
       AND (me.EVENT_GMT_DT < CONVERT(DATETIME, '2012-05-28 00:00:00', 102))
    

    I didn’t check the logic of your joins, I just moved them. Try and see if there’s still this syntax error..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this query: UPDATE Provinces SET Provinces.DefaultName=T2.Defaultname FROM Provinces INNER
I have problem with this SQL query: (SELECT tb1.id,tb1.bdate,tb1.jumpCard,tb1.publicImage,tb1.lastlogin FROM users AS tb1, online
I seem to have a problem with this SQL query: SELECT * FROM appts
HI, I have a problem with this query SELECT * FROM table WHERE `name`
i have a problem in this query select 7.115 + 2.885 result is 10.000
I have 4 tables and this query SELECT tag.id, title FROM tag LEFT JOIN
I have problem with optimize this query: SET @SEARCH = dokumentalne; SELECT SQL_NO_CACHE `AA`.`version`
I have this query in the controller $clientslist = $this->Client->query(SELECT client_name FROM clients WHERE
Let's say I have this query in PHP. $a = mysql_query(SELECT * FROM `users`
i have a problem during count data use this query: SELECT A.*, COUNT( B.Serial_number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.