Omega Owners Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Please play nicely.  No one wants to listen/read a keyboard warriors rants....

Pages: 1 [2] 3 4  All   Go Down

Author Topic: Another SQL query needed...  (Read 3353 times)

0 Members and 1 Guest are viewing this topic.

Chris_H

  • Omega Knight
  • *****
  • Offline Offline
  • Gender: Male
  • E London/Essex UK
  • Posts: 1716
    • Jag XF Portfolio S 3.0D
    • View Profile
Re: Another SQL query needed...
« Reply #15 on: 03 June 2010, 22:20:15 »

Here endeth the sequel sequel?  ;)
Logged
First Vauxhall - PABX Cresta; Previous, previous Vauxhall - 3.0 12v Senator CD; Previous Vauxhall Omega Elite 3.0V6 Saloon Auto

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #16 on: 03 June 2010, 22:36:38 »

Quote
Here endeth the sequel sequel?  ;)

yep..ended. if I wrote the actual code would be long enough but brain not performing well at the moment :P :-[

also there are other alternative solutions but too much alcohol in blood ;D
Logged

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #17 on: 03 June 2010, 22:41:08 »

Cheers cem :y - I used your SQL, worked out how to manipulate into my flexgrid, seems to work a treat :y

Thank you very much :y


Expect a harder query next time (probably over the weekend) ;D ;D
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #18 on: 03 June 2010, 22:43:37 »

Quote
Cheers cem :y - I used your SQL, worked out how to manipulate into my flexgrid, seems to work a treat :y

Thank you very much :y


Expect a harder query next time (probably over the weekend) ;D ;D

your are nearly passing my knowledge limits I hope I can solve next time :-[

Good night :y :y
« Last Edit: 03 June 2010, 22:45:18 by cem_devecioglu »
Logged

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #19 on: 03 June 2010, 23:00:06 »

Quote
Quote
Cheers cem :y - I used your SQL, worked out how to manipulate into my flexgrid, seems to work a treat :y

Thank you very much :y


Expect a harder query next time (probably over the weekend) ;D ;D

your are nearly passing my knowledge limits I hope I can solve next time :-[

Good night :y :y
Oh, its going to be a pig of a query.  If you can even think you can get the data out with a single query, then you are a better man than me ;D

I need to look at the tables and relationships again before I can give you a clue ;D
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #20 on: 04 June 2010, 09:43:41 »

Quote
Quote
Quote
Cheers cem :y - I used your SQL, worked out how to manipulate into my flexgrid, seems to work a treat :y

Thank you very much :y


Expect a harder query next time (probably over the weekend) ;D ;D

your are nearly passing my knowledge limits I hope I can solve next time :-[

Good night :y :y
Oh, its going to be a pig of a query.  If you can even think you can get the data out with a single query, then you are a better man than me ;D

I need to look at the tables and relationships again before I can give you a clue ;D

I hope I can help..sometimes I use temporary tables to hold the calculated tables if I'm lazy to use  matrix.. ;D
Logged

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #21 on: 04 June 2010, 15:37:52 »

Cem, that query is now in production use in my Brother's shop :y :y

Ready for the next one? ;D
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #22 on: 04 June 2010, 16:05:12 »

Quote
Cem, that query is now in production use in my Brother's shop :y :y

Ready for the next one? ;D

yep.. :y
Logged

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #23 on: 04 June 2010, 16:24:42 »

I need a query that will get the total stock value (actual cost, and current retail).

Current retail is easy: = Qty in stock * current retail price.

Actual cost is more tricky, as it needs to ascertain how many in stock, then step back through invoices to work out actual cost paid for those items in stock - ie, last invoice may say £100 cost, previous invoice may say £90. So if there are 3 in stock, 2 were on last invoice, and 2 were on previous invoice, it needs to work out 2 x £100 + 1 x £90. If that makes sense?

Tables:
Products
ProductID - unique key
Description - description of product
RetailPrice - current retail price
CostPrice - current cost price (but not used in this query?)

StockLevel
StockLevelID - unique key
BranchID - link to branches (query needs to simply work for all branches added together)
UnitsInStock - integer for how many in stock at branchid

Invoices:
InvoiceID - unique key
ProductID - link to products
Quantity - integer for number of this item recieved
CostPrice - price for each item on this invoice


Does that make sense?
Logged
Grumpy old man

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #24 on: 04 June 2010, 16:26:28 »

Would it help if I sent you an blank Access DB to show the DB layout?
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #25 on: 04 June 2010, 16:26:57 »

Quote
I need a query that will get the total stock value (actual cost, and current retail).

Current retail is easy: = Qty in stock * current retail price.

Actual cost is more tricky, as it needs to ascertain how many in stock, then step back through invoices to work out actual cost paid for those items in stock - ie, last invoice may say £100 cost, previous invoice may say £90. So if there are 3 in stock, 2 were on last invoice, and 2 were on previous invoice, it needs to work out 2 x £100 + 1 x £90. If that makes sense?

Tables:
Products
ProductID - unique key
Description - description of product
RetailPrice - current retail price
CostPrice - current cost price (but not used in this query?)

StockLevel
StockLevelID - unique key
BranchID - link to branches (query needs to simply work for all branches added together)
UnitsInStock - integer for how many in stock at branchid

Invoices:
InvoiceID - unique key
ProductID - link to products
Quantity - integer for number of this item recieved
CostPrice - price for each item on this invoice


Does that make sense?

yep.. will try now..  :y
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #26 on: 04 June 2010, 16:37:38 »

I see one problem, there must be product ID field
in stocklevel table or I cant sum up .. probably you forgot to write :-/
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #27 on: 04 June 2010, 16:39:41 »

Quote
Would it help if I sent you an blank Access DB to show the DB layout?

nope not necessary.. only field and table names are adequate..
« Last Edit: 04 June 2010, 16:39:55 by cem_devecioglu »
Logged

TheBoy

  • Administrator
  • *****
  • Offline Offline
  • Gender: Male
  • Brackley, Northants
  • Posts: 107026
  • I Like Lockdown
    • Whatever Starts
    • View Profile
Re: Another SQL query needed...
« Reply #28 on: 04 June 2010, 16:49:51 »

Quote
I see one problem, there must be product ID field
in stocklevel table or I cant sum up .. probably you forgot to write :-/
Yeah, my bad, there is a ProductID in table StockLevel...
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #29 on: 04 June 2010, 16:52:55 »

Quote
Quote
I see one problem, there must be product ID field
in stocklevel table or I cant sum up .. probably you forgot to write :-/
Yeah, my bad, there is a ProductID in table StockLevel...

now the simple one currentretail calculation


assuming you dont want calculate per branch instead global otherwise we must use Branchid in group by

select p.ppid,p.Description,p.Retailprice,curretail=p.Retailprice * s.cumstockforprod from
(select ppid=ProductID,Description,RetailPrice,CostPrice from Products) as p,
(select spid=ProductID,cumstockforprod=sum(UnitsInstock) from StockLevel group by ProductID) as s
on p.ppid=s.spid

and now solving the other..


« Last Edit: 04 June 2010, 16:54:56 by cem_devecioglu »
Logged
Pages: 1 [2] 3 4  All   Go Up
 

Page created in 0.014 seconds with 16 queries.