V_QUERY_STOCKSALE
Provides the ability to query stock sales.
Fields
Field | Field Type | Null | Description |
---|---|---|---|
ID | uniqueidentifier | System record ID | |
REVENUEID | uniqueidentifier | Revenue ID | |
SALEDATE | datetime | Date of sale | |
SALEAMOUNT | money | Sale amount | |
LOWPRICE | decimal(19, 4) | Low price | |
MEDIANPRICE | decimal(19, 4) | Median price | |
HIGHPRICE | decimal(19, 4) | High price | |
FEE | money | Fees | |
NUMBEROFUNITS | decimal(20, 3) | Units sold | |
SALEPOSTDATE | datetime | yes | GL post date |
SALEPOSTSTATUS | nvarchar(11) | yes | GL post status |
GAINLOSS | decimal(38, 6) | yes | Gain/loss |
NETPROCEEDS | money | yes | Net proceeds |
DATEADDED | datetime | Date added | |
DATECHANGED | datetime | Date changed | |
TSLONG | bigint | yes | Timestamp value |
ADDEDBY_APPLICATION | nvarchar(200) | yes | Added by application |
ADDEDBY_USERNAME | nvarchar(128) | yes | Added by user name |
CHANGEDBY_APPLICATION | nvarchar(200) | yes | Changed by application |
CHANGEDBY_USERNAME | nvarchar(128) | yes | Changed by user name |
UNSOLDAMOUNT | decimal(38, 6) | yes | Unsold amount |
UNITSREMAINING | decimal(38, 3) | yes | Units remaining |
TRANSACTIONSALEAMOUNT | money | Sale amount (transaction currency) | |
TRANSACTIONLOWPRICE | decimal(19, 4) | Low price (transaction currency) | |
TRANSACTIONMEDIANPRICE | decimal(19, 4) | Median price (transaction currency) | |
TRANSACTIONHIGHPRICE | decimal(19, 4) | High price (transaction currency) | |
TRANSACTIONFEE | money | Fees (transaction currency) | |
ORGANIZATIONSALEAMOUNT | money | Sale amount (organization currency) | |
ORGANIZATIONLOWPRICE | decimal(19, 4) | Low price (organization currency) | |
ORGANIZATIONMEDIANPRICE | decimal(19, 4) | Median price (organization currency) | |
ORGANIZATIONHIGHPRICE | decimal(19, 4) | High price (organization currency) | |
ORGANIZATIONFEE | money | Fees (organization currency) | |
TRANSACTIONGAINLOSS | decimal(38, 6) | yes | Gain/loss (transaction currency) |
TRANSACTIONNETPROCEEDS | money | yes | Net proceeds (transaction currency) |
ORGANIZATIONGAINLOSS | decimal(38, 6) | yes | Gain/loss (organization currency) |
ORGANIZATIONNETPROCEEDS | money | yes | Net proceeds (organization currency) |
TRANSACTIONUNSOLDAMOUNT | decimal(38, 6) | yes | Unsold amount (transaction currency) |
ORGANIZATIONUNSOLDAMOUNT | decimal(38, 6) | yes | Unsold amount (organization currency) |
BASECURRENCYID | uniqueidentifier | yes | Base currency ID |
BASEEXCHANGERATEID | uniqueidentifier | yes | Base exchange rate |
ORGANIZATIONEXCHANGERATEID | uniqueidentifier | yes | Organization exchange rate |
TRANSACTIONCURRENCYID | uniqueidentifier | yes | Transaction currency ID |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 3/19/2013 1:42:20 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=3.0.504.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE VIEW dbo.V_QUERY_STOCKSALE AS
select
STOCKSALE.ID,
REVENUEPAYMENTMETHOD.REVENUEID,
STOCKSALE.SALEDATE,
STOCKSALE.SALEAMOUNT,
STOCKSALE.LOWPRICE,
STOCKSALE.MEDIANPRICE,
STOCKSALE.HIGHPRICE,
STOCKSALE.FEE,
STOCKSALE.NUMBEROFUNITS,
STOCKSALE.SALEPOSTDATE,
STOCKSALE.SALEPOSTSTATUS,
STOCKSALE.SALEAMOUNT - (STOCKDETAIL.MEDIANPRICE * STOCKSALE.NUMBEROFUNITS) as GAINLOSS,
STOCKSALE.SALEAMOUNT - STOCKSALE.FEE as NETPROCEEDS,
STOCKSALE.DATEADDED,
STOCKSALE.DATECHANGED,
STOCKSALE.TSLONG,
ADDEDBY.APPLICATIONNAME as [ADDEDBY_APPLICATION],
ADDEDBY.USERNAME as [ADDEDBY_USERNAME],
CHANGEDBY.APPLICATIONNAME as [CHANGEDBY_APPLICATION],
CHANGEDBY.USERNAME as [CHANGEDBY_USERNAME],
(STOCKDETAIL.NUMBEROFUNITS - isnull((select sum(STOCKSALECUMULATIVE.NUMBEROFUNITS)
from dbo.STOCKSALE as STOCKSALECUMULATIVE
--The "GETLATESTTIME" date function has been inlined here for performance (the part with "dateadd(ms, -003...")...
where STOCKSALECUMULATIVE.SALEDATE <= dateadd(ms, -003, dateadd(d, 1, cast(cast(STOCKSALE.SALEDATE as date) as datetime)))
and STOCKSALECUMULATIVE.STOCKDETAILID = STOCKSALE.STOCKDETAILID)
, 0)) * STOCKDETAIL.MEDIANPRICE as UNSOLDAMOUNT,
STOCKDETAIL.NUMBEROFUNITS - isnull((select sum(STOCKSALECUMULATIVE.NUMBEROFUNITS)
from dbo.STOCKSALE as STOCKSALECUMULATIVE
--The "GETLATESTTIME" date function has been inlined here for performance (the part with "dateadd(ms, -003...")...
where STOCKSALECUMULATIVE.SALEDATE <= dateadd(ms, -003, dateadd(d, 1, cast(cast(STOCKSALE.SALEDATE as date) as datetime)))
and STOCKSALECUMULATIVE.STOCKDETAILID = STOCKSALE.STOCKDETAILID)
, 0) as UNITSREMAINING,
STOCKSALE.TRANSACTIONSALEAMOUNT,
STOCKSALE.TRANSACTIONLOWPRICE,
STOCKSALE.TRANSACTIONMEDIANPRICE,
STOCKSALE.TRANSACTIONHIGHPRICE,
STOCKSALE.TRANSACTIONFEE,
STOCKSALE.ORGANIZATIONSALEAMOUNT,
STOCKSALE.ORGANIZATIONLOWPRICE,
STOCKSALE.ORGANIZATIONMEDIANPRICE,
STOCKSALE.ORGANIZATIONHIGHPRICE,
STOCKSALE.ORGANIZATIONFEE,
STOCKSALE.TRANSACTIONSALEAMOUNT - (STOCKDETAIL.TRANSACTIONMEDIANPRICE * STOCKSALE.NUMBEROFUNITS) as TRANSACTIONGAINLOSS,
STOCKSALE.TRANSACTIONSALEAMOUNT - STOCKSALE.TRANSACTIONFEE as TRANSACTIONNETPROCEEDS,
STOCKSALE.ORGANIZATIONSALEAMOUNT - (STOCKDETAIL.ORGANIZATIONMEDIANPRICE * STOCKSALE.NUMBEROFUNITS) as ORGANIZATIONGAINLOSS,
STOCKSALE.ORGANIZATIONSALEAMOUNT - STOCKSALE.ORGANIZATIONFEE as ORGANIZATIONNETPROCEEDS,
(STOCKDETAIL.NUMBEROFUNITS - isnull((select sum(STOCKSALECUMULATIVE.NUMBEROFUNITS)
from dbo.STOCKSALE as STOCKSALECUMULATIVE
--The "GETLATESTTIME" date function has been inlined here for performance (the part with "dateadd(ms, -003...")...
where STOCKSALECUMULATIVE.SALEDATE <= dateadd(ms, -003, dateadd(d, 1, cast(cast(STOCKSALE.SALEDATE as date) as datetime)))
and STOCKSALECUMULATIVE.STOCKDETAILID = STOCKSALE.STOCKDETAILID)
, 0)) * STOCKDETAIL.TRANSACTIONMEDIANPRICE as TRANSACTIONUNSOLDAMOUNT,
(STOCKDETAIL.NUMBEROFUNITS - isnull((select sum(STOCKSALECUMULATIVE.NUMBEROFUNITS)
from dbo.STOCKSALE as STOCKSALECUMULATIVE
--The "GETLATESTTIME" date function has been inlined here for performance (the part with "dateadd(ms, -003...")...
where STOCKSALECUMULATIVE.SALEDATE <= dateadd(ms, -003, dateadd(d, 1, cast(cast(STOCKSALE.SALEDATE as date) as datetime)))
and STOCKSALECUMULATIVE.STOCKDETAILID = STOCKSALE.STOCKDETAILID)
, 0)) * STOCKDETAIL.ORGANIZATIONMEDIANPRICE as ORGANIZATIONUNSOLDAMOUNT,
STOCKSALE.BASECURRENCYID,
STOCKSALE.BASEEXCHANGERATEID,
STOCKSALE.ORGANIZATIONEXCHANGERATEID,
STOCKSALE.TRANSACTIONCURRENCYID
/*#EXTENSION*/
from dbo.STOCKSALE
inner join dbo.STOCKDETAIL on STOCKSALE.STOCKDETAILID = STOCKDETAIL.ID
inner join dbo.REVENUEPAYMENTMETHOD on STOCKDETAIL.ID = REVENUEPAYMENTMETHOD.ID
left join dbo.CHANGEAGENT as ADDEDBY on ADDEDBY.ID = STOCKSALE.ADDEDBYID
left join dbo.CHANGEAGENT as CHANGEDBY on CHANGEDBY.ID = STOCKSALE.CHANGEDBYID