Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I have a query that I want to return a field and then a value.

Posted on 2007-07-25
1
Medium Priority
?
205 Views
Last Modified: 2010-03-20
I have a query that I want to return a field and then a value.
Here is the basic query:
select abr_id
from tblStateLicense
where ABR_ID IN
                          (SELECT DISTINCT abr_id
                            FROM          tblMoc
                            WHERE     MOCStatus <> 'Inactive' and MOCStatus <> 'Complete'
                      AND expireyear = '2007')
Order by ABR_ID

What I want to do next is to check a field in the db (tblStatelicense.expirationdate) . It is a date field and I need to check it again today date (getDAte()) and return a value of Y if they have not expired and N if they have expired.  There maybe multiple returns for one ID and some of those rows retunred will be expired and some won.  But if they have at least on non-expired date then they should get a yes.

so my recordset would be    ID  Expired
                                            1234   N
Thanks in advance.  Using SQL 2000

0
Comment
Question by:TimSweet220
1 Comment
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 19567489
select abr_id , Case when ExpirationDate < CONVERT(varchar,getdate(),112)  THEN 'Y'  ELSE 'N' END as Expired
from tblStateLicense
where ABR_ID IN
                          (SELECT DISTINCT abr_id
                            FROM          tblMoc
                            WHERE     MOCStatus <> 'Inactive' and MOCStatus <> 'Complete'
                      AND expireyear = '2007')
Order by ABR_ID
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question