I wanted to multiply two values from two different tables.
I have a quantity filed stored in one table and a unit/rate field in another.
How can i write the sql statement based on a condition and store that multiplied result for further actions.

Recommended Answers

All 2 Replies

can anybody check this statement,if there is a mistake please do tell me.

cmd = New OleDbCommand("SELECT quantity * rate as VALUE FROM sub_pay_item_quantity,sub_pay_item_unit_rate" & _
                             "WHERE [sub_pay_item_quantity.sub item] and [sub_pay_item_unit_rate.sub item]='" & subitem & "' and [sub_pay_item_quantity.bridge type] ='" & bridgetype & "'" & _
                             "and [sub_pay_item_quantity.span]='" & span & "'", conn)

MSDN Multiply in SQL

Exactly as you have done there (providing both values are numeric data types,) just to be sure in case you get NULL values I would use the ISNULL function to return a zero if there is a NULL:

SELECT ISNULL(quantity,0) * ISNULL(rate, 0) as VALUE FROM 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.