You are on page 1of 3

--------**** Created By :- Mr.

Khalid Husain Ali Ahmed
***------------------------

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

--sp_helptext'getprice_cash_fut_opt'

--'sp_helptext'getprice_cash_fut_opt'

Create procedure getprice_cash_fut_opt
@userid varchar(30)
as
begin
select dp.Scriptname as Scripcode,dp.Exchange as
Exng,/*dp.Type,*/convert(numeric(15,2),ncp.lasttradeprice) as LTP,
convert(varchar(107),ncp.lasttradetime,25)as Last_Trade_Time,
dp.Buyrate,
dp.Quantity as BuyQty,convert(numeric(15,2),(dp.Quantity*dp.Buyrate))as Total_Inv,
convert(numeric(15,2),ncp.lasttradeprice*dp.Quantity) as Current_Val,
--convert(numeric(15,2),ncp.lasttradeprice-ncp.closeprice)*dp.Quantity as TodayPL,
'0' as TodayPL,
convert(numeric(15,2),(ncp.lasttradeprice*Quantity))-
convert(numeric(15,2),(Quantity*Buyrate))as OverallPL,
convert(numeric(15,2),((ncp.lasttradeprice*Quantity)-
(Quantity*Buyrate))*100/(dp.Quantity*dp.Buyrate)) as 'Percent'
,status=
case when(dp.Quantity*dp.Buyrate)<(ncp.lasttradeprice*dp.Quantity) then 'PROFIT'
when(dp.Quantity*dp.Buyrate)>(ncp.lasttradeprice*dp.Quantity) then 'LOSS'
when(dp.Quantity*dp.Buyrate)=(ncp.lasttradeprice*dp.Quantity) then 'SAME'
end
from power_view..dp as dp inner join tickerplantdatabase..Bsecurrentprices as ncp
on dp.scriptname=ncp.scripcode where dp.type='cash' and exchange='BSE' and
dp.userid=@userid

UNION ALL

select dp.Scriptname as Scripcode,dp.Exchange as
Exng,/*dp.Type,*/convert(numeric(15,2),ncp.lasttradeprice) as LTP,
convert(varchar(107),ncp.lasttradetime,25)as Last_Trade_Time,
dp.Buyrate,
dp.Quantity as BuyQty,convert(numeric(15,2),(dp.Quantity*dp.Buyrate))as Total_Inv,
convert(numeric(15,2),ncp.lasttradeprice*dp.Quantity) as Current_Val,
convert(numeric(15,2),ncp.lasttradeprice-ncp.openprice)*dp.Quantity as TodayPL,
convert(numeric(15,2),(ncp.lasttradeprice*Quantity))-
convert(numeric(15,2),(Quantity*Buyrate))as OverallPL,
convert(numeric(15,2),((ncp.lasttradeprice*Quantity)-
(Quantity*Buyrate))*100/(dp.Quantity*dp.Buyrate)) as 'Percent'
,status=
case when(dp.Quantity*dp.Buyrate)<(ncp.lasttradeprice*dp.Quantity) then 'PROFIT'
when(dp.Quantity*dp.Buyrate)>(ncp.lasttradeprice*dp.Quantity) then 'LOSS '
when(dp.Quantity*dp.Buyrate)=(ncp.lasttradeprice*dp.Quantity) then 'SAME'
end
from power_view..dp as dp inner join tickerplantdatabase..Nsecurrentprices as ncp
on dp.scriptname=ncp.scripcode where dp.type='cash' and exchange='NSE' and
dp.userid=@userid

UNION ALL

select dp.Scriptname+dp.expirydate as Scripcode,dp.Exchange as
Exng,/*dp.Type,*/convert(numeric(15,2),ncp.lasttradeprice) as LTP,
convert(varchar(107),ncp.lasttradetime,25)as Last_Trade_Time,
dp.Buyrate,
dp.Quantity as BuyQty,convert(numeric(15,2),(dp.Quantity*dp.Buyrate))as Total_Inv,
convert(numeric(15,2),ncp.lasttradeprice*dp.Quantity) as Current_Val,
convert(numeric(15,2),ncp.lasttradeprice-ncp.openprice)*dp.Quantity as TodayPL,
convert(numeric(15,2),(ncp.lasttradeprice*Quantity))-
convert(numeric(15,2),(Quantity*Buyrate))as OverallPL,
convert(numeric(15,2),((ncp.lasttradeprice*Quantity)-
(Quantity*Buyrate))*100/(dp.Quantity*dp.Buyrate)) as 'Percent'
,status=
case when(dp.Quantity*dp.Buyrate)<(ncp.lasttradeprice*dp.Quantity) then 'PROFIT'
when(dp.Quantity*dp.Buyrate)>(ncp.lasttradeprice*dp.Quantity) then 'LOSS '
when(dp.Quantity*dp.Buyrate)=(ncp.lasttradeprice*dp.Quantity) then 'SAME'
end
from power_view..dp as dp inner join tickerplantdatabase..foNsecurrentprices as
ncp
on dp.scriptname=ncp.scripcode where dp.type='future' and dp.Expirydate=ncp.sid
and exchange='NSE' and dp.userid=@userid

UNION ALL

select dp.Scriptname+dp.expirydate+dp.optiontype+convert(char(20),dp.strikeprice)
as Scripcode,dp.Exchange as
Exng,/*dp.Type,*/convert(numeric(15,2),ncp.lasttradeprice) as LTP,
convert(varchar(107),ncp.lasttradetime,25)as Last_Trade_Time,
dp.Buyrate,
dp.Quantity as BuyQty,convert(numeric(15,2),(dp.Quantity*dp.Buyrate))as Total_Inv,
convert(numeric(15,2),ncp.lasttradeprice*dp.Quantity) as Current_Val,
convert(numeric(15,2),ncp.lasttradeprice-ncp.openprice)*dp.Quantity as TodayPL,
convert(numeric(15,2),(ncp.lasttradeprice*Quantity))-
convert(numeric(15,2),(Quantity*Buyrate))as OverallPL,
convert(numeric(15,2),((ncp.lasttradeprice*Quantity)-
(Quantity*Buyrate))*100/(dp.Quantity*dp.Buyrate)) as
'Percent'
,status=
case when(dp.Quantity*dp.Buyrate)<(ncp.lasttradeprice*dp.Quantity) then 'PROFIT'
when(dp.Quantity*dp.Buyrate)>(ncp.lasttradeprice*dp.Quantity) then 'LOSS '
when(dp.Quantity*dp.Buyrate)=(ncp.lasttradeprice*dp.Quantity) then 'SAME'
end
from power_view..dp as dp inner join tickerplantdatabase..foNsecurrentprices as
ncp
on dp.scriptname=ncp.scripcode and
dp.expirydate+dp.optiontype+convert(varchar(15),dp.strikeprice)=ncp.sid
where dp.type='OPTION' and exchange='NSE' and dp.userid=@userid
end
SET NOCOUNT OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO