Getting the row base on column in a data set

Hi

My record set is like below(only sample):

I need to get the if "col 7" is both  rows are null I need to get the one single row from the two record.


col1  col2 col3          col4      col 5       col 6                                         col7
1       28       2ES-03B        2ES      ER 2ES      2003-10-23 00:00:00.000      NULL      
1        28       2ES-03B        2ES      ER 2ES      1994-01-01 00:00:00.000      NULL      

how can I achieve this?

thanks
ken hanseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
Would that "one row" look like this?

col1  col2     col3              col4      col 5          col 6                                         col7
1       28       2ES-03B        2ES      ER 2ES      2003-10-23 00:00:00.000      NULL

or, this?

col1  col2     col3              col4      col 5          col 6                                         col7
1        28       2ES-03B        2ES      ER 2ES      1994-01-01 00:00:00.000      NULL
0
ken hanseAuthor Commented:
First one
0
PortletPaulfreelancerCommented:
try this
SELECT
     [col1], [col2], [col3], [col4], [col5], MAX(Col6) AS [col6], MAX(Col7) AS [col7]
FROM Table1
GROUP BY
     [col1], [col2], [col3], [col4], [col5]
HAVING
     SUM(CASE WHEN [col7] IS NULL Then 1 ELSE 0 END) = 2
;

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ken hanseAuthor Commented:
Thanks, it is require bit more, I need to return the rows that are not matching the Having criteria as well while limiting one row from de duplication.
0
PortletPaulfreelancerCommented:
Do the other rows ALWAYS have non-null [col7] values?
If so try this:

SELECT
     col1, col2, col3, col4, col5, MAX(Col6) AS col6, MAX(Col7) AS col7
FROM Table1
GROUP BY
     col1, col2, col3, col4, col5
HAVING
     SUM(CASE WHEN col7 IS NULL Then 1 ELSE 0 END) IN (0, 2)
;

Open in new window


If the above is not a solution. Please.
Supply sample data that covers all known cases to be solved, and provide the "expected result" for that sample.

{+ edit}
you could also try the same query except EXCLUDE the having clause completely.
0
ken hanseAuthor Commented:
I have attached the excel file with some sample data. and desire result is only highlighted column.
duprecords.xlsx
0
ken hanseAuthor Commented:
sorry - Highlighted rows
0
PortletPaulfreelancerCommented:
Working with just that list:

Why not just filter out any rows where start_dttm is 1/01/1994  12:00:00 AM

e.g.

select *
from that_list
where start_dttm > '19940101'

highlighted rows all after 1994-01-01
0
ken hanseAuthor Commented:
the date can be vary. So, Can't reply only that date. this is just a samples
0
PortletPaulfreelancerCommented:
Try using row_number() then. This uses an ORDER which will give you the latest date's row. That is, for each unique combination of col1, col2, col3, col4, col5 you will get ONE ROW that will have the latest date value of col6. Adjust the order to suit for col7
select
*
from (
   select
   *
   , row_number() over(partition by col1, col2, col3, col4, col5 order by col6 DESC, col7) as rn
  from your_source
  ) as derived
where rn = 1

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ken hanseAuthor Commented:
thanks for the help. it worked
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.