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 8434491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:40:15+00:00 2026-06-10T06:40:15+00:00

;WITH n AS ( SELECT problemID, StationName, problemCode, ProblemCreateDate, probCount, c = COUNT(*) OVER

  • 0
;WITH n AS  
( 
  SELECT problemID, StationName, problemCode, ProblemCreateDate, probCount, 
    c = COUNT(*) OVER (PARTITION BY StationName, problemCode), 
    rn = ROW_NUMBER() OVER  
    ( 
      PARTITION BY StationName, problemCode ORDER BY ProblemCreateDate DESC, problemID DESC 
    ) 
  FROM dbo.tblProblems
) 
 SELECT problemID, StationName, problemCode, ProblemCreateDate, c 
 FROM n WHERE rn = 1; 

there is another table named tblCustomers , with a column isAssistent Type(bit)

I tried doing inner join but it’s too complicated for me and I get an error when trying to apply the filter of inner join with

tblCustomers where tblCustomers.isAssistent =1

I will be very grateful and happy to know how to write the correct syntax

ReEdit

inner join tblCustomers on tblProblems.CustID = tblCustomers.custID

errors , with one of my last tries

Msg 4104, Level 16, State 1, Line 14 The multi-part identifier
“tblProblems.CustID” could not be bound. Msg 4104, Level 16, State 1,
Line 12 The multi-part identifier “tblproblems.problemID” could not be
bound. Msg 4104, Level 16, State 1, Line 12 The multi-part identifier
“tblproblems.custID” could not be bound. Msg 4104, Level 16, State 1,
Line 12 The multi-part identifier “tblproblems.StationName” could not
be bound. Msg 4104, Level 16, State 1, Line 12 The multi-part
identifier “tblproblems.problemCode” could not be bound. Msg 4104,
Level 16, State 1, Line 12 The multi-part identifier
“tblproblems.ProblemCreateDate” could not be bound.

this is the wild guess i made :

;WITH n AS  
( 
  SELECT tblCustomers.*,tblproblems.problemID, tblproblems.StationName, tblproblems.problemCode, tblproblems.ProblemCreateDate, tblproblems.probCount, 
    c = COUNT(*) OVER (PARTITION BY tblproblems.StationName, tblproblems.problemCode), 
    rn = ROW_NUMBER() OVER  
    ( 
      PARTITION BY tblproblems.StationName, tblproblems.problemCode ORDER BY tblproblems.ProblemCreateDate DESC, tblproblems.problemID DESC 
    ) 
  FROM dbo.tblProblems
  inner join tblCustomers on tblProblems.CustID = tblCustomers.custID
) 
SELECT tblCustomers.*, tblproblems.problemID, tblproblems.custID, tblproblems.StationName, tblproblems.problemCode, tblproblems.ProblemCreateDate, c 
FROM n 
inner join tblCustomers on tblProblems.CustID = tblCustomers.custID
WHERE rn = 1; 

the purpose was to have select result of tblProblems only when tblCustomers.isAssistent=1

  • 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-10T06:40:17+00:00Added an answer on June 10, 2026 at 6:40 am

    Your query outside with is wrong, it should be

    SELECT tblCustomers.*, n.problemID, n.custID, 
               n.StationName, n.problemCode, n.ProblemCreateDate, c 
    FROM n 
    inner join tblCustomers on n.CustID = tblCustomers.custID
    WHERE rn = 1; 
    

    And why are you joining tblcustomers again?

    You can just do:

    ;WITH n AS  
    
    ( 
      SELECT tblCustomers.*,tblproblems.problemID, tblproblems.StationName, 
             tblproblems.problemCode, tblproblems.ProblemCreateDate,
             tblproblems.probCount, 
        c = COUNT(*) OVER 
            (PARTITION BY tblproblems.StationName, tblproblems.problemCode), 
        rn = ROW_NUMBER() OVER  
        ( 
          PARTITION BY tblproblems.StationName, tblproblems.problemCode
          ORDER BY tblproblems.ProblemCreateDate DESC, tblproblems.problemID DESC 
        ) 
      FROM dbo.tblProblems
      inner join tblCustomers on tblProblems.CustID = tblCustomers.custID
      WHERE tblCustomers.isAssistent =1
    
    ) 
    SELECT n.* FROM n where rn = 1
    

    If you need only problems data

    ;WITH n AS  
    
    ( 
      SELECT tblproblems.problemID, tblproblems.StationName, 
             tblproblems.problemCode, tblproblems.ProblemCreateDate,
             tblproblems.probCount, 
        c = COUNT(*) OVER 
            (PARTITION BY tblproblems.StationName, tblproblems.problemCode), 
        rn = ROW_NUMBER() OVER  
        ( 
          PARTITION BY tblproblems.StationName, tblproblems.problemCode
          ORDER BY tblproblems.ProblemCreateDate DESC, tblproblems.problemID DESC 
        ) 
      FROM dbo.tblProblems
      inner join tblCustomers on tblProblems.CustID = tblCustomers.custID
      WHERE tblCustomers.isAssistent =1
    
    ) 
    SELECT n.* FROM n where rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: merge dbo.tblProblems as target using ( select max(problemID), StationName, problemCode,
In SQLSERVER/MSSQL, here's the problem: SELECT * from [Translation Color] order by [Language Code]
My problem comes from HTML dropdown select not able to preserve multiple consecutive whitespaces
My problem is easy to explain: SELECT * FROM sphinx LIMIT 512 OFFSET 1
The problem is probably quite simple. $q = SELECT id FROM users WHERE name
Strange problem. My Query looks like SELECT DISTINCT ID, `etcetc`, `if/elses over muliple joined
i have problem using LIKE structure in DB2 : for example: select * from
HI I try to run : select year, regr_slope(sum(sale_count),year) as slope, from products group
I have the following problem: I select data from a DB, and for each
I have following Problem SELECT * from map_user_sticker WHERE map_user_sticker.user_id = 7; +----+---------+------------+ |

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.