troubleshooting Question

Create a New Field based on existing field with Where clause

Avatar of Grayson Hampton
Grayson Hampton asked on
* T-SQLSQL
9 Comments1 Solution25 ViewsLast Modified:
I have the following query, which builds a new field successfully.
I need the (ABS(SplitRate) > '15.00000' in the Where clause to only be used when calculating the "NewField" results and not the entire query.



with cte as (
      select pr.CompanyID, pr.JobType, pr.TempID, pr.CustomerNumber, pr.OfficeID, pr.SBUID, pr.JobNumber, pr.ConsultantID, pr.BatchID,
            row_number() over(partition by pr.CompanyID, pr.JobType, pr.TempID, pr.CustomerNumber, pr.OfficeID, pr.SBUID, pr.JobNumber, pr.ConsultantID, pr.BatchID
                                    order by pr.CompanyID, pr.JobType, pr.TempID, pr.CustomerNumber, pr.OfficeID, pr.SBUID, pr.JobNumber, pr.ConsultantID, pr.BatchID) rn
      from [Temp_Rept] pr
WHERE (ABS(SplitRate) > '15.00000')
 and pr.[CustomerNumber] = 113517
     
)
select CompanyID, JobType, TempID, CustomerNumber, OfficeID, SBUID, JobNumber, ConsultantID, BatchID,
      case when rn=1 then 1 else 0 end NewField
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros