MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 January 7th, 2005, 09:37 AM
chale100 chale100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 chale100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Filter on one column but display another

I have a date column and a value column. I want to display the value column based on the last date. MAX (Date)

I tried using MAX for the date column but that displays the last date.

Any Ideas?

Reply With Quote
  #2  
Old January 7th, 2005, 10:37 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Code:
select v
from t
where d in (
   select max(d) 
     from t)

Reply With Quote
  #3  
Old January 7th, 2005, 11:14 AM
Aforsythe Aforsythe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 104 Aforsythe User rank is Private First Class (20 - 50 Reputation Level)Aforsythe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 22 h 8 m 10 sec
Reputation Power: 4
Select Distinct value from table order by date

this sounds like what you are looking for, if not, just elaborate a bit and I or someone else here may be able to help you.

Reply With Quote
  #4  
Old January 7th, 2005, 12:12 PM
chale100 chale100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 chale100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is the script

--Query to return list price for product by product family--

SELECT prf.description as PRICE_FAMILY, pdf.description as PRODUCT_FAMILY, pro.code as ITEM_NUMBER, pro.description as PRODUCT, uom.description as UOM, uom.conversion_factor as COUNT, lst.price as LIST_PRICE, pro.cost as OVERRIDE_COST_EACH, rci.price_received as LAST_COST
from product_families pdf
join products pro
on (pdf.pdf_id = pro.pdf_id and pdf.pdf_source_id = pro.pro_source_id)
join packaged_products pkp
on (pkp.pro_id = pro.pro_id and pkp.pkp_source_id = pro.pro_source_id)
join units_of_measure uom
on (pkp.uni_id = uom.uni_id and pkp.uni_source_id = uom.uni_source_id)
join receipt_items rci
on (pkp.pkp_id = rci.pkp_id and pkp.pkp_source_id = rci.pkp_source_id)
join price_families prf
on (prf.prf_id = pro.prf_id and prf.prf_source_id = pro.prf_source_id)
LEFT outer join list_prices lst
on (pkp.pkp_id = lst.pkp_id and pkp.pkp_source_id = lst.pkp_source_id)
where pkp.delivery = 'Y' and pro.out_service_date is NULL -- and rci.price_received in (select MAX (rci.datetime_posted))
ORDER BY pdf.description ASC, pro.product ASC

I do not know if this will help but I still can not get it. I have a database that keeps up with the purchase price of goods, so everytime it is purchased it adds a line to the table to put in the purchase price and the post time. I want to get the last post time to populate my price.

Reply With Quote
  #5  
Old January 7th, 2005, 12:24 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Code:
SELECT prf.description as PRICE_FAMILY, pdf.description as PRODUCT_FAMILY, pro.code as ITEM_NUMBER, pro.description as PRODUCT, uom.description as UOM, uom.conversion_factor as COUNT, lst.price as LIST_PRICE, pro.cost as OVERRIDE_COST_EACH, rci.price_received as LAST_COST
from product_families pdf
join products pro
on (pdf.pdf_id = pro.pdf_id and pdf.pdf_source_id = pro.pro_source_id)
join packaged_products pkp
on (pkp.pro_id = pro.pro_id and pkp.pkp_source_id = pro.pro_source_id)
join units_of_measure uom
on (pkp.uni_id = uom.uni_id and pkp.uni_source_id = uom.uni_source_id)
join receipt_items rci
on (pkp.pkp_id = rci.pkp_id and pkp.pkp_source_id = rci.pkp_source_id)
join price_families prf
on (prf.prf_id = pro.prf_id and prf.prf_source_id = pro.prf_source_id)
LEFT outer join list_prices lst
on (pkp.pkp_id = lst.pkp_id and pkp.pkp_source_id = lst.pkp_source_id)
where pkp.delivery = 'Y' 
and pro.out_service_date is NULL 
and rci.datetime_posted in (
  select MAX (datetime_posted)
 from receipt_items)
ORDER BY pdf.description ASC, pro.product ASC

Reply With Quote
  #6  
Old January 7th, 2005, 12:31 PM
chale100 chale100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 chale100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's it! Thank you so much for your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Filter on one column but display another


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT