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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:22:04+00:00 2026-05-14T07:22:04+00:00

I have a problem with ROW_NUMBER() , if i used it with DISTINCT in

  • 0

I have a problem with ROW_NUMBER() , if i used it with DISTINCT in the following Query
I have 2 scenarios:
1- run this query direct : give me for example 400 record as a result
2- uncomment a line which start with [–Uncomment1–] : give me 700 record as a result
it duplicated some records not all the records

what I want is to solve this problem or to find any way to show a row counter beside each row, to make a [where rownumber between 1 and 30] –Uncomment2–

if I put the whole query in a table, and then filter it , it is work but it still so slow

waiting for any feedback and I will appreciate that

Thanks in advance

SELECT * FROM 
(SELECT Distinct  CRSTask.ID AS TaskID,
      CRSTask.WFLTaskID,
  --Uncomment1--       ROW_NUMBER() OVER (ORDER By  CRSTask.CreateDate asc ) AS RowNum ,
      CRSTask.WFLStatus AS Task_WFLStatus,
      CRSTask.Name AS StepName,
      CRSTask.ModifiedDate AS Task_ModifyDate,
      CRSTask.SendingDate AS Task_SendingDate,
      CRSTask.ReceiveDate AS Task_ReceiveDate,
      CRSTask.CreateDate AS Task_CreateDate,
      CRS_Task_Recipient_Vw.Task_CurrentSenderName,
      CRS_Task_Recipient_Vw.Task_SenderName,
      CRS_INFO.ID AS CRS_ID,
      CRS_INFO.ReferenceNumber,
      CRS_INFO.CRSBeneficiaries,

      CRS_INFO.BarCodeNumber,
      ISNULL(dbo.CRS_FNC_GetTaskReceiver(CRSTask.ID), '') + ' ' + ISNULL 

(CRS_Organization.ArName, '') 
     AS OrgName,
      CRS_Info.IncidentID,
      COALESCE(CRS_Subject.ArSubject, 'غير مبين') AS ArSubject,
      COALESCE(CRS_INFO.Subject, 'Blank Subject') AS CRS_Subject,
      CRS_INFO.Mode,
      CRS_Task_Recipient_Vw.ReceiverID,
      CRS_Task_Recipient_Vw.ReceiverType,
      CRS_Task_Recipient_Vw.CC,
      Temp_Portal_Users_View.ID AS CRS_LockedByID,
      Temp_Portal_Users_View.ArabicName AS CRS_LockedByName,
      CRSDraft.ID AS DraftID,
      CRSDraft.Type AS DraftType,
      CASE 
     WHEN CRS_Folder = 1 THEN Task_SenderName
     WHEN CRS_Folder = 2 THEN Task_SenderName
     WHEN CRS_Folder = 3 THEN Task_CurrentSenderName
      END AS SenderName,
      CRS_Task_Folder_Vw.CRS_Folder,
      CRS_INFO.Status,
      CRS_INFO.CRS_Type,
      CRS_Type.arName AS CRS_Type_Name
  FROM   CRS_Task_Folder_Vw
      LEFT OUTER JOIN CRSTask
     ON  CRSTask.ID = CRS_Task_Folder_Vw.TaskID
      LEFT OUTER JOIN CRS_INFO
     ON  CRS_INFO.ID = CRSTask.CRSID
      LEFT OUTER JOIN CRS_Subject
     ON  COALESCE(
       SUBSTRING(
        CRS_INFO.Subject,
        CHARINDEX('_', CRS_INFO.Subject) + 1,
        LEN(CRS_INFO.Subject)
       ),
       'Blank Subject'
      ) = CRS_Subject.ID
      LEFT OUTER JOIN CRSInfoAttribute
     ON  CRS_INFO.ID = CRSInfoAttribute.ID
      LEFT OUTER JOIN CRS_Organization
     ON  CRS_Organization.ID = CRSInfoAttribute.SourceID
      LEFT OUTER JOIN CRS_Type
     ON  CRS_INFO.CRS_Type = CRS_Type.ID
      LEFT OUTER JOIN CRS_Way
     ON  CRS_INFO.CRS_Send_Way = CRS_Way.ID
      LEFT OUTER JOIN CRS_Priority
     ON  CRS_INFO.CRS_Priority_ID = CRS_Priority.ID
      LEFT OUTER JOIN CRS_SecurityLevel
     ON  CRS_INFO.SecurityLevelID = CRS_SecurityLevel.ID
      LEFT OUTER JOIN Portal_Users_View
     ON  Portal_Users_View.ID = CRS_INFO.CRS_Initiator
      LEFT OUTER JOIN AD_DOC_TBL
     ON  CRS_INFO.DocumentID = AD_DOC_TBL.ID
      LEFT OUTER JOIN CRSTask AS Temp_CRSTask
     ON  CRSTask.ParentTask = Temp_CRSTask.ID
      LEFT OUTER JOIN Portal_Users_View AS Temp_Portal_Users_View
     ON  Temp_Portal_Users_View.ID = AD_DOC_TBL.Lock_User_ID
      LEFT OUTER JOIN Portal_Users_View AS Temp1_Portal_Users_View
     ON  Temp1_Portal_Users_View.ID = CRS_INFO.ClosedBy
      LEFT OUTER JOIN CRSDraft
     ON  CRSTask.ID = CRSDraft.TaskID
      LEFT OUTER JOIN CRS_Task_Recipient_Vw
     ON  CRSTask.ID = CRS_Task_Recipient_Vw.TaskID 
      --LEFT OUTER JOIN  CRSTaskReceiverUsers     ON CRSTask.ID = 

CRSTaskReceiverUsers.CRSTaskID AND CRS_Task_Recipient_Vw.ReceiverID = CRSTaskReceiverUsers.ReceiverID

      LEFT OUTER JOIN CRSTaskReceiverUserProfile
     ON  CRSTask.ID = CRSTaskReceiverUserProfile.TaskID
  WHERE  Crs_Info.SUBJECT <> 'Blank Subject'
      AND (CRS_INFO.Subject NOT LIKE '%null%')
      AND CRS_Info.IsDeleted <> 1 
       /* AND CRSTask.WFLStatus <> 6 
       AND CRSTask.WFLStatus <> 8  */
      AND (
        (
         CRS_Task_Recipient_Vw.ReceiverID IN (1, 29)
         AND CRS_Task_Recipient_Vw.ReceiverType IN (1, 3, 4)
        )
       )
      AND 1 = 1

)Codes
--Uncomment2--  WHERE Codes.RowNum BETWEEN 1 AND 30
ORDER BY
       Codes.Task_CreateDate ASC
  • 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-05-14T07:22:04+00:00Added an answer on May 14, 2026 at 7:22 am

    If the issue is that you have duplicate rows and DISTINCT is failing because the ordinal row number is making each row unique; try (with DISTINCT):

    DENSE_RANK() OVER (ORDER By CRSTask.CreateDate asc)
    

    You can also remove the DISTINCT and GROUP BY everything in the CTE.

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

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have the following query: WITH cte AS ( SELECT windowId, frameIndx, elemIndx, comment,
I have found this example on StackOverflow: var people = new List<Person> { new
i used v s 2010 i have one problem..when i delete more then one
I have a major problem getting this to work properly. Here is the deal.
I have used a custom array adapter to populate my list view.The problem i
Here is my problem. I have a select statement something like this: select *
I'll simplify the problem as much as possible: I have an oracle table: row_priority,
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names

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.