sobota, 20 października 2018

Giełda - Procedura emisji


procedure [dbo].[pStockEmission](
@id_stock int,
@setNumberStocks int,
@setStockPrice money
) as

begin
declare @getnumberOfStocks int
declare @stocksPrice money
declare @maxStockCount int
declare @TransactionPrice money
if(@setStockPrice > 0)
begin
set @stocksPrice = @setStockPrice
end
else
begin
select @stocksPrice = stock_pricie from Stock where stock_id = @id_stock and stock_aktywny = 1
end
--ilosc akcji w rynku
select @getnumberOfStocks = stock_count,@maxStockCount = stock_maxCount
from Stock
where
stock_id = @id_stock
if((@getnumberOfStocks + @setNumberStocks) <= @maxStockCount)
begin
--kwota transakcji
set @TransactionPrice = @setNumberStocks * @stocksPrice
--rozpoczecie emisji
print 'insert'
INSERT INTO [dbo].[MarketSquare]
([stock_id],[wal_id],[mark_numberOfShares],[mark_aktywny]
,[mark_sharePriceBuy],[bs_id],[mark_sharePriceSell],[mark_dataStart],[mark_dataEnd],[ mark_TransactionPrice])
VALUES (@id_stock,null,@setNumberStocks,1,0,4,@stocksPrice,GETDATE(),null,@TransactionPrice)
Update Stock set
stock_count = @getnumberOfStocks + @setNumberStocks,
stock_date = GETDATE()
where
stock_id = @id_stock
print @getnumberOfStocks + @setNumberStocks
end
else
begin
print 'ilosc akcji do emisji za duża'
end
end

Brak komentarzy:

Prześlij komentarz

 Po wielu miesiącach przerwy Czteroletnim exodusie do bloga ismartdev, który zdechł w zeszłym roku w listopadzie, na powrót wstąpiłem w ten ...