I'm having difficulty with a query I'm making...well, attempting. I'm working with 5 columns here: Name, SeNo, OrderNumber, Type and expirationDatethe query looks like this:Select Name, SeNumber, OrderNumber, Type = (Select Case When ISNULL(ExpirationDate, '1/10/2020') <= getdate() Then '[Retired]' + '(' + Type + ') 'When ISNULL(ExpirationDate, '1/10/2020') > getdate() Then '(' + Type = ') ' END), ExpirationDateFrom MapTableOrder by SeNo, OrderNUmber
OrderNumber is a designation of numeric order, used in conjunction with Type. Basically, it ranges from 1 to N for each Type. Now, here's the problem I'm having:The query result may look like this:Name SeNo OrderNumber Type ExpirationDate---------------------------------------------------------------------John 100 1 [Retired](Physical) 12/31/2021Jane 100 2 Physical 11/11/2000Joe 100 3 [Retired](Email) 11/12/2022Mary 100 4 Email 10/10/1999Alan 101 1 [Retired](Physical) 12/31/2021Gary 101 2 Physical 11/11/2000Kate 101 3 [Retired](Email) 11/12/2022Marie 101 4 Email 10/10/1999
I want it to look like this:Name SeNo OrderNumber Type ExpirationDate--------------------------------------------------------------------Jane 100 2 Physical 11/11/2000Mary 100 4 Email 10/10/1999John 100 1 [Retired](Physical) 12/31/2021Joe 100 3 [Retired](Email) 11/12/2022Gary 101 2 Physical 11/11/2000Marie 101 4 Email 10/10/1999Alan 101 1 [Retired](Physical) 12/31/2021Kate 101 3 [Retired](Email) 11/12/2022
See that? It orders it on SeNo, then based upon if the Type has "[Retired]" prepended to Type, and finally the OrderNumber. But the caveat here is the orderno is predicated on the Type and I am not sure how to realize this query result. That is the problem at hand. If anyone can help me, I'd really appreciate it. Thank you.