Unix Technical Forum

SQL-Query Access by Date

This is a discussion on SQL-Query Access by Date within the SQL Server forums, part of the Microsoft SQL Server category; --> Example: Date | ItemCode | Stock_In_qty | Stock_Out_qty | Bal_qty ------------------------------------------------------------------ 12/09/2003 | A100 | 20 | 0 | ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 05:14 AM
Cady Steldyn
 
Posts: n/a
Default SQL-Query Access by Date

Example:

Date | ItemCode | Stock_In_qty | Stock_Out_qty | Bal_qty
------------------------------------------------------------------

12/09/2003 | A100 | 20 | 0 | 20
25/10/2003 | A100 | 0 | 10 | *10

I need to query an Access database that will take field 3 (Stock_In_qty)
plus any bal from
the above row in the calculated field (Bal_qty) minus field 4
(Stock_Out_qty) that will show me
the latest Bal_qty, note that Bal_qty = (Stock_In_Qty - Stock_Out_Qty)
AS Bal_Qty.As an Example in the above scenario,
the Bal_qty in the second row on 25/10/2003 is (0 + 20(Row 1) - 10) =
*10.Stock out not necessary comes from
Stock In, it could simply be taken out from the Bal_qty balance from
previous month, any clues?

can anyone help? Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 05:14 AM
John Bell
 
Posts: n/a
Default Re: SQL-Query Access by Date

Hi

As this is an access query you may get a better answer from an Access
newsgroup, but you may want to create a query similar to the following:

SELECT S.Date, S.ItemCode, S.Stock_In_Qty, S.Stock_Out_Qty,
( SELECT SUM(t.Stock_In_qty) - SUM(t.Stock_Out_qty) FROM Stock t WHERE
S.date >= t.date ) AS TotalStock
FROM Stock S

In Access you probably have to create a predefined query instead of the
subquery and say call it StockBallance

SELECT Date, SUM(Stock_In_qty) - SUM(Stock_Out_qty) as TotalStock FROM
Stock GROUP BY Date

Then you query could be:

SELECT S.Date, S.ItemCode, S.Stock_In_Qty, S.Stock_Out_Qty, b.TotalStock
FROM Stock S
INNER StockBallance b on b.date = s.date

John

"Cady Steldyn" <dcartford@yahoo.ca> wrote in message
news:4143d11e$0$26085$c397aba@news.newsgroups.ws.. .
> Example:
>
> Date | ItemCode | Stock_In_qty | Stock_Out_qty | Bal_qty
> ------------------------------------------------------------------
>
> 12/09/2003 | A100 | 20 | 0 | 20
> 25/10/2003 | A100 | 0 | 10 | *10
>
> I need to query an Access database that will take field 3 (Stock_In_qty)
> plus any bal from
> the above row in the calculated field (Bal_qty) minus field 4
> (Stock_Out_qty) that will show me
> the latest Bal_qty, note that Bal_qty = (Stock_In_Qty - Stock_Out_Qty)
> AS Bal_Qty.As an Example in the above scenario,
> the Bal_qty in the second row on 25/10/2003 is (0 + 20(Row 1) - 10) =
> *10.Stock out not necessary comes from
> Stock In, it could simply be taken out from the Bal_qty balance from
> previous month, any clues?
>
> can anyone help? Thanks
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com