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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:02:21+00:00 2026-06-12T04:02:21+00:00

is it possible to put a boolean expression with max or min into a

  • 0

is it possible to put a boolean expression with max or min into a nullif() statemtent?

for example

select 
    min(a) as b ---grabbing first value
    ,max(a) as  c --- grabbing last value but could be same as min value, this is the problem
    ,nullif(min(a), (min(a) = max(a))) ---my idea for a solution that didnt work
   from table

trying to weed out duplicate rows when a field has a value that only happens 1 time. I am thinking there may be a way to do this with counting and then weeding out all values with a value over 1 but am not sure how to accomplish that. working on sql server 2005, need this in t-sql if possible, anything that will work on the server is ok though.

edit to provide more info:
i am looking at a status history for orders in an order management system that tags each time a correction is requested with an id. the id’s are unique and numerical. in this format 1234 each orderid is unique and numerical as well in this format 1111111.2. a represents the unique correction id. I want to look at the order, and if one correction id has already happened to grab the next one ideally, and the next after that and so on if possible. At very minimum i would want the MAX value and MIN value. i cannot just do two columns because that would count the min value twice (using my example) and will not give me accurate data

was trying to be simple with my example but its not providing enough info, here is more:

SELECT Cast(oi.orderid AS VARCHAR(MAX)) + '.' 
                 + Cast(oi.orderitemid AS VARCHAR(MAX)) AS OrderNumber,
       Min(oici.orderitemcorrectionid)                  AS a,
       Max(oici.orderitemcorrectionid)                  AS b
FROM   Orderitems oi
       LEFT JOIN orderitemcorrections oic
         ON oic.orderid = oi.orderid
            AND oic.orderitemid = oi.orderitemid
       LEFT JOIN orderitemcorrectionissues oici
         ON oici.orderitemcorrectionid = oic.orderitemcorrectionid
       LEFT JOIN correctiontypes ct
         ON ct.correctiontypeid = oici.correctiontypeid
GROUP  BY Cast(oi.orderid AS VARCHAR(MAX)) + '.' 
                   + Cast(oi.orderitemid AS VARCHAR(MAX)) 

sample table data of above query:

OrderNumber a   b
1098048.1   1   2
1098210.1   160 160
1098222.1   78  78
1098300.1   31  31
1098408.1   4   4
1098462.1   224 224
1098468.1   602 602
1098492.2   1457 1457

above is data where a and b are the same
below is where they are different but i want to null any duplicates from a to b

1100268.1   181 191
1100256.1   306 379

more data, not grouped to show duplicates for rows. — sample raw data

OrderNumber orderitemcorrectionid
1098048.1   1
1098048.1   2
1098210.1   160
1098210.1   160
  • 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-12T04:02:24+00:00Added an answer on June 12, 2026 at 4:02 am

    You can achieve the nullifying by using UNION, which removes duplicate rows. I would do it like this

    ;with tmp AS (
        select
        CAST(oi.orderid as VARCHAR(MAX))+'.'+CAST(oi.orderitemid as VARCHAR(MAX)) as OrderNumber
        ,min(oici.orderitemcorrectionid) as a
        ,max(oici.orderitemcorrectionid) as b
    
        FROM
        Orderitems oi
        left join orderitemcorrections oic on oic.orderid = oi.orderid and oic.orderitemid = oi.orderitemid
        left join orderitemcorrectionissues oici on oici.orderitemcorrectionid = oic.orderitemcorrectionid
        left join correctiontypes ct on ct.correctiontypeid = oici.correctiontypeid
        GROUP BY 
        CAST(oi.orderid as VARCHAR(MAX))+'.'+CAST(oi.orderitemid as VARCHAR(MAX))
    )
    select OrderNumber, a
    from tmp
    union
    select OrderNumber, b
    from tmp
    

    This puts the a’s and b’s into different rows, with Union taking care of removing duplicates.

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

Sidebar

Related Questions

Hi guy it's possible put in the application Badge some letter? Something like ON
(Edit: put possible solution at end) I'm a C/C++ programmer who is learning Objective
Would it be possible to put install THG on a shared drive and let
Is it possible to put an instance of android.location.Address with Intent to another activity?
Is it possible to put a macro in a macro in c++? Something like:
In C++/CLI it is not possible to put pointers to native C++ classes in
Ajax.ActionLink(Link name,....) it is possible to put checkbox in place of Link name ?
Possible Duplicate: How many Python classes should I put in one file? Coming from
Possible Duplicate: How to center div horizontally and vertically I need to put image
Can anybody put lime light on what possible problems might emerge if an application

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.