cancel
Showing results for 
Search instead for 
Did you mean: 

Special prices with gross profit query

former_member239716
Participant
0 Kudos

Hi guys is there anyway that I could calculate gross profit in the below query without having to dump it into excel? So that we can run the report and it shows the gross profit on each line of the customers special pricing.

SELECT T1.[CardCode] AS 'BP Code', T1.[ItemCode] AS 'Item No.', T1.[Price] AS 'Special Price', T0.[LastPurPrc] AS 'Last Purchase Price' FROM [dbo].[OITM] T0 INNER JOIN [dbo].[OSPP] T1 ON T1.[ItemCode] = T0.[ItemCode]

WHERE T1.CardCode = [%0]

Accepted Solutions (1)

Accepted Solutions (1)

Johan_H
Active Contributor

Hi Roy,

Please give this a try:

SELECT T1.[CardCode] AS 'BP Code'
     , T1.[ItemCode] AS 'Item No.'
     , T1.[Price] AS 'Special Price'
     , T0.[LastPurPrc] AS 'Last Purchase Price' 
     , (T1.[Price] - T0.[LastPurPrc]) AS 'Gross Profit'
FROM [dbo].[OITM] T0 
     INNER JOIN [dbo].[OSPP] T1 ON T1.[ItemCode] = T0.[ItemCode]
WHERE T1.CardCode = '[%0]'

Regards,

Johan

Answers (1)

Answers (1)

former_member239716
Participant

Amazing - thank you Johan and this also prompted me to realise a small change to allow for the profit to be shown as a % - thank you very much for this.

SELECT T1.[CardCode] AS 'BP Code'
, T1.[ItemCode] AS 'Item No.'
, T1.[Price] AS 'Special Price'
, T0.[LastPurPrc] AS 'Last Purchase Price'
, (T1.[Price] - T0.[LastPurPrc]) / (T1.[Price]) * 100 AS 'Gross Profit %'
FROM [dbo].[OITM] T0
INNER JOIN [dbo].[OSPP] T1 ON T1.[ItemCode] = T0.[ItemCode]
WHERE T1.CardCode = '[%0]'