Results 1 to 8 of 8
  1. #1
    buntybunty is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    4

    Cool URGENT: Can anyone help to fix Access SQL - Kudos if you have great skills

    tblProducts Table
    tProductID Text - PK


    tProductName Text


    tblProductsPrice Table
    tProductID Text - FK (VAlues will be like OJFDKERWER)
    iProductDate DateTime
    lProductNPrice Number Double


    I am storing the values of the tables as below -


    tblProducts
    OJFDKERWER, AcerLaptop
    WPTRWJWERK, HP Laptop


    tblProductsPrice
    OJFDKERWER, 01-Sep-15, 500
    OJFDKERWER, 02-Sep-15, 500
    OJFDKERWER, 03-Sep-15, 500
    OJFDKERWER, 04-Sep-15, 525
    OJFDKERWER, 05-Sep-15, 495


    Suppose today is 05-Sep then the query should list the price change from previous day (only if lower than before)


    Please suggest me the SQL query which will run in access 2013 (not in SQL Server)


    Many Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make query Q1 that pulls the current prices,
    make Q2 that pulls the NEW prices and join to Q1 on [tProductID]
    Q2 will be an update query, where the criteria will be: (if Q2<Q1) update price

    field : Q2.[
    lProductNPrice]
    citeria: <
    Q1.[lProductNPrice]

    set:
    Q1.[lProductNPrice] = Q2.[lProductNPrice]



  3. #3
    buntybunty is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    4

    thanks

    Thanks, can you pls help me with the access query - many thanks struggling urgent

    Quote Originally Posted by ranman256 View Post
    make query Q1 that pulls the current prices,
    make Q2 that pulls the NEW prices and join to Q1 on [tProductID]
    Q2 will be an update query, where the criteria will be: (if Q2<Q1) update price

    field : Q2.[
    lProductNPrice]
    citeria: <
    Q1.[lProductNPrice]

    set:
    Q1.[lProductNPrice] = Q2.[lProductNPrice]



  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    To pull data from another record of same table - review http://allenbrowne.com/subquery-01.html#AnotherRecord

    To retrieve the most recent record for each product - review http://allenbrowne.com/subquery-01.html#TopN

    Exactly what do you need to do? If tblProducts does not store the price, then no UPDATE action is needed.

    Do you want to retrieve the most recent price for each product? Do you want to calculate the change in price?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    buntybunty is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    4

    Thumbs up Change in Price

    Hi -Yes, I want to calculate change in price (dont want the recent price)

    ie. if there is a price change today, I need to be alerted (subsequent actions I can take via web page) but the list of records wherein price has increased or decreased. There is no update action in the tbproducts as it does not store price info

    Quote Originally Posted by June7 View Post
    To pull data from another record of same table - review http://allenbrowne.com/subquery-01.html#AnotherRecord

    To retrieve the most recent record for each product - review http://allenbrowne.com/subquery-01.html#TopN

    Exactly what do you need to do? If tblProducts does not store the price, then no UPDATE action is needed.

    Do you want to retrieve the most recent price for each product? Do you want to calculate the change in price?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    To find out if there is a price change, need to pull the two most recent records (today and yesterday - TOP 2 ?) for each product and calculate the difference. Seems to me will need both of the examples I provided links to.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    buntybunty is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    4
    Can give me sql pls

    Quote Originally Posted by june7 View Post
    to find out if there is a price change, need to pull the two most recent records (today and yesterday - top 2 ?) for each product and calculate the difference. Seems to me will need both of the examples i provided links to.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Exactly why do you need to do this? Why would this be useful? What do you want to do with the results? What if the data is like:

    tblProductsPrice
    OJFDKERWER, 01-Sep-15, 500
    OJFDKERWER, 02-Sep-15, 500
    OJFDKERWER, 03-Sep-15, 500
    OJFDKERWER, 04-Sep-15, 525
    OJFDKERWER, 05-Sep-15, 495
    OJFDKERWER, 06-Sep-15, 510

    The latest value on 06-Sep is an increase but is less than the value of 04-Sep.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. CRUD application and VBA skills
    By adeling in forum Access
    Replies: 4
    Last Post: 11-07-2013, 02:42 PM
  2. My reporting solution works great BUT....
    By tstoneami in forum Reports
    Replies: 1
    Last Post: 08-31-2013, 08:37 PM
  3. Kudos!!!
    By Stephanie53 in forum Access
    Replies: 3
    Last Post: 06-05-2013, 11:35 AM
  4. Replies: 11
    Last Post: 04-04-2010, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums