Pass DC No as a parameter from frontend and change set @query as below
set @query = 'DECLARE @DCNo INT;
SET @DCNo ='+Cast(@DCNO as VARCHAR)+';
SELECT DCNo,DCDate,FromSupName,FromAddress,FromContNo,ToSupName,ToAddress,ToContNo,RefferedBy, ' + @colsName + '
from
(select DCDate, DCNo,FromSupName,FromAddress,FromContNo,ToSupName,ToContNo,RefferedBy,ToAddress, ItemCode +''_''+col col, value
from
(select DCDate, ItemCode, DCNo,FromSupName,FromAddress,FromContNo,ToSupName,ToAddress,ToContNo,RefferedBy,
cast(Qty as numeric(10, 2)) totalcount,
cast(Rate as numeric(10, 2)) totalamount
from Vw_InOutWard WHERE DCNo=@DCNO ) src
UNPIVOT
(value for col in (totalcount, totalamount)) unpiv ) s
pivot (sum(value) for col in (' + @cols + ')) p '