MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 9th, 2012, 12:41 PM
lynbarr lynbarr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 2 lynbarr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 35 sec
Reputation Power: 0
Complicated join

I'm trying to write a view in SQL2000 (it's my client's environment, and they're not ready to upgrade).

I have a table called "Customers" and another called "CreditCards." One customer may have many credit cards.

The "CreditCards" table has a varchar field "ExpDate" and the values in this column are all four digits, mmyy.

I am trying to figure out how to write a view that returns one line per customer, showing the credit card details with the latest expiration date.

For example, Customer John Doe has two cards. One expires 0313 and the other expires 0514. I want my view to show one line for John Doe, with the details for the 0514 card.

Can anyone think of a good way to do this?

Thanks!

Reply With Quote
  #2  
Old May 9th, 2012, 03:41 PM
joeflinthiggins joeflinthiggins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 joeflinthiggins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 20 m 33 sec
Reputation Power: 0
A good place to start would be to flip the year and month around and take the max expiration date before joining to the Customers table. Once you have the expiration date formatted as yymm instead of mmyy, then a max() will return the proper record.

Reply With Quote
  #3  
Old May 9th, 2012, 04:11 PM
lynbarr lynbarr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 2 lynbarr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by joeflinthiggins
A good place to start would be to flip the year and month around and take the max expiration date before joining to the Customers table. Once you have the expiration date formatted as yymm instead of mmyy, then a max() will return the proper record.


Great idea, Joe, thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Complicated join

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap