How to multiply values from different rows and different columns?
This what the table looks like.
Code Items Unit QTY Price Total
------- --------- ---- ---- ----- -----
HTM001 Cable Tie pcs null 1.00 ?
HTM001s Cable Tie null 20 null
and I tried a query like this...
SELECT VRIJ1 FROM dbo.INVELE WHERE FK_BODEFINITOIN_USERDEFINED IN (894) AS QTY,
SELECT RESTWRDE FROM dbo.INVELE WHERE FK_BODEFINITOIN_USERDEFINED IN (898) AS PRICE,
(QTY*PRICE) AS TOTAL
FROM dbo.INVELE
then I got these:
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'AS'.
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'AS'.
what I want is to like this 20*1.00=Total
.
Anyone Please help开发者_C百科!!!
;WITH T1(QTY, CODE) AS
(
SELECT VRIJ1, LEFT(CODE, 7)
FROM dbo.INVELE
WHERE FK_BODEFINITION_USERDEFINED IN (894)
),
T2(PRICE, CODE) AS
(
SELECT RESTWRDE, CODE
FROM dbo.INVELE
WHERE FK_BODEFINITION_USERDEFINED IN (898)
)
SELECT T1.QTY,
T2.PRICE,
T1.QTY*T2.PRICE AS TOTAL
FROM T1
INNER JOIN T2
ON T1.CODE = T2.CODE
精彩评论