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 3352 times)

0 Members and 1 Guest are viewing this topic.

Sixstring

  • Omega Baron
  • *****
  • Offline Offline
  • Gender: Male
  • Lydney, Gloucestershire
  • Posts: 2127
  • Its just GOTTA be a big V6. Mmm....NOS........
    • View Profile
Re: Another SQL query needed...
« Reply #30 on: 04 June 2010, 16:54:26 »

Blimey, Jamie........you fluent in upper mongolian too???


I understand none of this!!
Logged
Self confessed Electro-Mechanical nut, Guitarist/Singer and Motorcyclist. Drives an estate due to all the equipment he has to carry,Electrickery fiddler who loves Automatics and BIG Vee engines.

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #31 on: 04 June 2010, 17:02:44 »

for calculating exact values I need another table
which defines for a product from which price how many has been sold to design the query..

I have experienced same problem in the past so I hold
the sold numbers and their prices in another seperate table.. :-/

as actually for a same product if the price is different its something different ..

otherwise it will be approximative..

but if not available  I can use some averaging methods..
« Last Edit: 04 June 2010, 17:09:37 by cem_devecioglu »
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #32 on: 04 June 2010, 17:22:55 »

ok checking another method..first in first out-fifo
« Last Edit: 04 June 2010, 18:07:34 by cem_devecioglu »
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #33 on: 04 June 2010, 17:29:50 »

as the invoice id is an incremental number
we can use that.. but you will also need to code in vb6..preparing..
« Last Edit: 04 June 2010, 17:42:37 by cem_devecioglu »
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #34 on: 04 June 2010, 18:02:32 »

Here is :y   

ps: all connections must be opened simultaneously
like
dim adoconnection1 As New ADODB.Connection
dim adoconnection2 As New ADODB.Connection
dim adoconnection3 As New ADODB.Connection

dim rsl As New ADODB.Recordset
dim rs2 As New ADODB.Recordset
dim rs3 As New ADODB.Recordset

cp1 = "Provider=sqloledb;uid=sa;pwd=password;server=servername;database=dbname ;"

    Set adoconnection1 = New ADODB.Connection
    adoconnection1.CommandTimeout = 2000
    adoconnection1.ConnectionTimeout = 10
    adoconnection1.Open cp1
   

    Set adoconnection2 = New ADODB.Connection
    adoconnection2.CommandTimeout = 2000
    adoconnection2.ConnectionTimeout = 10
    adoconnection2.Open cp1
   
   
    Set adoconnection3 = New ADODB.Connection
    adoconnection3.CommandTimeout = 2000
    adoconnection3.ConnectionTimeout = 10
    adoconnection3.Open cp1



gridrow=0

txt1="select ProductID,Description,RetailPrice,CostPrice from Products order by ProductID" 'read every product id

Set rs1 = New ADODB.Recordset
rs1.Open txt1, adoconnection1


While rs1.EOF = False   

  txt2="select cumstockforprod=sum(UnitsInStock) from StockLevel where ProductID=" & rs1!ProductID
  Set rs2 = New ADODB.Recordset
  rs2.Open txt2, adoconnection2
  cumstockforprod=rs2!cumstockforprod ' get cumulative stock for that product

  suminvoicecount=0
  sumactualcost=0.0

  txt3="select Quantity,CostPrice from Invoices where ProductID=" & rs1!ProductID & " order by InvoiceID desc"  ' this part is critical

  Set rs3 = New ADODB.Recordset
  rs3.Open txt3, adoconnection3

  while rs3.eof and suminvoicecount<cumstockforprod
    if suminvoicecount+rs3!Quantity <=cumstockforprod then

       suminvoicecount=suminvoicecount + rs3!Quantity
       sumactualcost=sumactualcost + rs3!quantity*rs3!CostPrice
   
    else

       suminvoicecount=suminvoicecount+(cumstockforprod-suminvoicecount) '
       sumactualcost=sumactualcost + (cumstockforprod-suminvoicecount)*rs3!CostPrice

    end if
      
    rs3.movenext
  Wend

   '  now write to grid or print
 
   
    gridrow=gridrow+1  '

    grid.rows=gridrow+1

 
   grid(gridrow,1).text=rs1!Description
   grid(gridrow,2).text=sumactualcost
   
   

 rs1.MoveNext

Wend

« Last Edit: 04 June 2010, 18:36:35 by cem_devecioglu »
Logged

jereboam

  • Omega Knight
  • *****
  • Offline Offline
  • Gender: Male
  • Suffolk
  • Posts: 1786
    • 1999 Omega Elite 3.0
    • View Profile
Re: Another SQL query needed...
« Reply #35 on: 04 June 2010, 18:19:04 »

I'm awfully glad I didn't respond to the original post.  It's not really an SQL problem.

Fairly simple to solve in PL/SQL, but you haven't got Oracle.  Pity about that. :)
Logged
I can be handy mending a fuse - but stuff the Isle of Wight

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #36 on: 04 June 2010, 18:22:15 »

SQL 2000 - 2005 also have extra properties that I did not use..and remember stored procedures are not allowed..
Logged

Omegatoy

  • Omega Baron
  • *****
  • Offline Offline
  • UK
  • Posts: 3688
    • View Profile
Re: Another SQL query needed...
« Reply #37 on: 04 June 2010, 18:27:30 »

got halfway through this post and fell asleep!!!
 if you fellas have to work this out daily then i dont envy any of you, my life is much simpler even with all the car problems we get!! all i do is undo nuts and bolts and repair and paint body panels, life is for enjoying!! lolol clever chaps on here!!!

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #38 on: 04 June 2010, 18:34:53 »

Quote
got halfway through this post and fell asleep!!!
 if you fellas have to work this out daily then i dont envy any of you, my life is much simpler even with all the car problems we get!! all i do is undo nuts and bolts and repair and paint body panels, life is for enjoying!! lolol clever chaps on here!!!

unfortunately yes.. and sometimes you are expected to write more than a thousand lines per day during development period.. :(

and agree your idea.. life is for enjoying :y

for my next life I hope I can remember that :'(
Logged

Omegatoy

  • Omega Baron
  • *****
  • Offline Offline
  • UK
  • Posts: 3688
    • View Profile
Re: Another SQL query needed...
« Reply #39 on: 04 June 2010, 18:39:01 »

Quote
Quote
got halfway through this post and fell asleep!!!
 if you fellas have to work this out daily then i dont envy any of you, my life is much simpler even with all the car problems we get!! all i do is undo nuts and bolts and repair and paint body panels, life is for enjoying!! lolol clever chaps on here!!!

unfortunately yes.. and sometimes you are expected to write more than a thousand lines per day during development period.. :(

and agree your idea.. life is for enjoying :y

for my next life I hope I can remember that :'(

hope so to Cem, what you do would give me a major headache everyday, I take my hat off to you :y

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #40 on: 04 June 2010, 18:40:09 »

Jaime , in sql 2005 this transposition or pivoting is a bit easier..  :y

http://geekswithblogs.net/lorint/archive/2006/08/04/87166.aspx
Logged

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #41 on: 04 June 2010, 18:45:02 »

Quote
Quote
Quote
got halfway through this post and fell asleep!!!
 if you fellas have to work this out daily then i dont envy any of you, my life is much simpler even with all the car problems we get!! all i do is undo nuts and bolts and repair and paint body panels, life is for enjoying!! lolol clever chaps on here!!!

unfortunately yes.. and sometimes you are expected to write more than a thousand lines per day during development period.. :(

and agree your idea.. life is for enjoying :y

for my next life I hope I can remember that :'(

hope so to Cem, what you do would give me a major headache everyday, I take my hat off to you :y

Thanks Omegatoy :y :y :y :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 #42 on: 05 June 2010, 10:43:07 »

Cem - as there is replication going on, we cannot guarantee that InvoiceID is in order. There is a date field in Invoices though.

Actually, I may have given you misinformation about tables....


Invoice:
InvoiceID
InvoiceDate

InvoiceDetails:
InvoiceDetailID
InvoiceID
ProductID
CostPrice
Quantity

(tables have other stuff, doubt relevent though)


We can assume proper stock rotation, so that those left in stock are the most recently invoiced.
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 #43 on: 05 June 2010, 10:44:34 »

Quote
Jaime , in sql 2005 this transposition or pivoting is a bit easier..  :y

http://geekswithblogs.net/lorint/archive/2006/08/04/87166.aspx
Sadly, this also has to work in Jet/Access, so unlikely I can use SQL2K5 specific functions :(
Logged
Grumpy old man

cem_devecioglu

  • Guest
Re: Another SQL query needed...
« Reply #44 on: 05 June 2010, 11:20:21 »

a bit busy day sorry,  will arrange the code accordingly the first time I'm available :y
Logged
Pages: 1 2 [3] 4  All   Go Up
 

Page created in 0.016 seconds with 17 queries.