A source query should looks like this:
select s.code,p.date,p.rs from Price as p
inner join SCH as s
on s.CODE=p.CODE
where s.CODE in (18,20,50,909) AND NOT p.rs IS NULL
and p.date BETWEEN ' +' '''+@fromdate+''' '+ ' and '+' '''+@todate+''' '+ '
[EDIT]
If sourcce table does not contain
NULL
values, you have to filter pivot table:
SELECT pt.<Fields>
FROM (
) AS st
PIVOT (...) AS pt
WHERE NOT pt.[909] IS NULL
Another way is to replace NULLs with default values via using
COALESCE function[
^]:
SELECT COALESCE(pt.[18], 0) AS [18]