the procedure should be this
Create proc [dbo].[Usp_customerpaystatustest1]
(
@layoutid numeric(18,0)
)
As
begin
DECLARE @cols AS NVARCHAR(MAX),
--@cold AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(insno) --,' + QUOTENAME(s.paymentstst)
from tbl_payinstallment where layoutid=@layoutid
--ORDER BY s.insno
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT receiptno,layoutid, ' + @cols + ' from
(
select a.layoutid,a.receiptno,a.insno,a.paymentstatus from tbl_payinstallment as a
where a.layoutid= ' + CAST(@layoutid AS varchar(18)) + '
) x
pivot
(
min(paymentstatus)
for
insno in (' + @cols + ')
) p '
execute(@query)
end
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
No comments:
Post a Comment