Hi coder,
Let me explain what is my requirment. I need to check if i have customers with different productid if yes then i have to check if they have any producttype null or not in case any of the customerid have NULL producttype then flag for both the customerid should be N else Y
For example :I have a table in which i have many columns. PFB the table stucture
Customerid productid producttype
1 a x
1 b Null
2 c y
2 d y
3 e z
3 f Null
what i want is like below:
Customerid Productid Productype flag
1 a x N
1 b Null N
2 c y Y
2 d y Y
3 e z N
3 f Null N
till now what i have done
;with cte as
(
select * from test where customerid in
(select customerid from test group by customerid having count(*) >1
) )
from this i collect all the customerid who have more then one productid and different producttpe now i want to add the flag part.
Please let me know if this approach is good and how can i achieve the next thing.
Thanks in advance !!
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhilash J APosted Jul 4, 2017, 11:05 AM
Yif none of the product types for the customer areNull;Nif there is more than one product and at least one product type isNull; andNullif there is only one product, and the product type isNull.If you need to change that, you should be able to modify the second
CASEstatement.Anil JhaPosted Jul 4, 2017, 9:48 AM
Abhilash J APosted Jul 4, 2017, 9:06 AM
Anil JhaPosted Jul 4, 2017, 7:50 AM