Click here to Skip to main content
15,891,657 members
Home / Discussions / Database
   

Database

 
AnswerRe: Help Creating a Temp Table Pin
Blue_Boy3-Sep-09 11:23
Blue_Boy3-Sep-09 11:23 
GeneralRe: Help Creating a Temp Table Pin
Hulicat3-Sep-09 13:52
Hulicat3-Sep-09 13:52 
AnswerRe: Help Creating a Temp Table Pin
Niladri_Biswas6-Nov-09 20:24
Niladri_Biswas6-Nov-09 20:24 
QuestionHelp Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG3-Sep-09 10:16
JNBG3-Sep-09 10:16 
AnswerRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
Abhishek Sur5-Sep-09 12:12
professionalAbhishek Sur5-Sep-09 12:12 
GeneralRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG5-Sep-09 12:33
JNBG5-Sep-09 12:33 
GeneralRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG5-Sep-09 14:17
JNBG5-Sep-09 14:17 
QuestionHelp for an SQL query Pin
sazd13-Sep-09 3:40
sazd13-Sep-09 3:40 
I have been guided to put my question to this forum.
I am using vb express and MsAccess as database.
I am trying to write a query for the calculation of Stock.
My tables are as under:
PId PDate ItemId Description Price Quantity Amount
1 28/8/2009 1 Coca Cola Normal 1,00 10 10,00
2 28/8/2009 2 Coca Cola Zero 1,00 5 5,00
3 29/8/2009 1 Coca Cola Normal 1,00 5 5,00
4 29/8/2009 2 Coca Cola Zero 1,00 10 10,00

Data in Sales Table is as under:

SId SDate ItemId Description Price Quantity Amount
1 30/8/2009 1 Coca Cola Normal 2,70 2 5,40
2 30/8/2009 2 Coca Cola Zero 2,70 3 7,10
3 31/8/2009 1 Coca Cola Normal 2,70 1 2,70
4 31/8/2009 2 Coca Cola Zero 2,70 2 2,70

I tried something like this to have balance of stock at any date or interval between two dates

Dim cmdText As String = "SELECT pt.ItemId, pt.Description, SUM(pt.Quantity)AS QuantityPurchased, SUM(st.Quantity) AS QuantitySold, (SUM(pt.Quantity) - SUM(st.Quantity)) AS Balance FROM PurchaseTable pt INNER JOIN SalesTable st ON pt.ItemId=st.ItemId WHERE pt.PDate Between @START and @END GROUP BY pt.ItemId, pt.Description"

If con.State = ConnectionState.Closed Then con.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(cmdText, con)
cmd.CommandType = CommandType.Text

cmd.Parameters.AddWithValue("@START", OleDb.OleDbType.Date).Value = TextBox1.Text
cmd.Parameters.AddWithValue("@END", OleDb.OleDbType.Date).Value = TextBox2.Text

Dim dr As OleDb.OleDbDataReader

If con.State = ConnectionState.Closed Then con.Open()
dr = cmd.ExecuteReader
If Not dr.HasRows Then
MessageBox.Show("No Records Found for Date: " & TextBox1.Text)
Else
MessageBox.Show("Record found for Date: " & TextBox1.Text)
ListView1.Items.Clear()
ListView1.ForeColor = Color.DarkRed
ListView1.GridLines = True

While dr.Read
Dim ls As New ListViewItem(dr.Item("ItemId").ToString())
ls.SubItems.Add(dr.Item("Description").ToString())
ls.SubItems.Add(dr.Item("QuantityPurchased").ToStr ing())
ls.SubItems.Add(dr.Item("QuantitySold").ToString() )
ls.SubItems.Add(dr.Item("Balance").ToString())
ListView1.Items.Add(ls)
End While
End If
But i could not get the desired results. Please advise what i am doing wrong with this.
Thanks
AnswerRe: Help for an SQL query Pin
David Skelly3-Sep-09 6:03
David Skelly3-Sep-09 6:03 
GeneralRe: Help for an SQL query Pin
sazd13-Sep-09 8:35
sazd13-Sep-09 8:35 
GeneralRe: Help for an SQL query Pin
David Skelly3-Sep-09 22:34
David Skelly3-Sep-09 22:34 
Questioneasy_odbc leak memory Pin
Ruscoff3-Sep-09 0:05
Ruscoff3-Sep-09 0:05 
AnswerRe: easy_odbc leak memory Pin
Ashfield3-Sep-09 1:30
Ashfield3-Sep-09 1:30 
GeneralRe: easy_odbc leak memory Pin
Ruscoff3-Sep-09 2:47
Ruscoff3-Sep-09 2:47 
GeneralRe: easy_odbc leak memory Pin
Ashfield3-Sep-09 3:36
Ashfield3-Sep-09 3:36 
QuestionScript Check Pin
Mustafa Ismail Mustafa2-Sep-09 9:46
Mustafa Ismail Mustafa2-Sep-09 9:46 
AnswerRe: Script Check Pin
Mycroft Holmes2-Sep-09 18:06
professionalMycroft Holmes2-Sep-09 18:06 
GeneralRe: Script Check Pin
Mustafa Ismail Mustafa2-Sep-09 20:47
Mustafa Ismail Mustafa2-Sep-09 20:47 
Questionupdate issue Pin
Tauseef A2-Sep-09 2:30
Tauseef A2-Sep-09 2:30 
AnswerRe: update issue Pin
Blue_Boy2-Sep-09 2:38
Blue_Boy2-Sep-09 2:38 
AnswerRe: update issue Pin
David Mujica2-Sep-09 3:32
David Mujica2-Sep-09 3:32 
AnswerRe: update issue Pin
Abhishek Sur2-Sep-09 9:43
professionalAbhishek Sur2-Sep-09 9:43 
AnswerRe: update issue Pin
Niladri_Biswas2-Sep-09 17:18
Niladri_Biswas2-Sep-09 17:18 
Questione-blood bank Pin
noo.dyab2-Sep-09 1:07
noo.dyab2-Sep-09 1:07 
AnswerRe: e-blood bank Pin
Ashfield2-Sep-09 1:28
Ashfield2-Sep-09 1:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.