Click here to Skip to main content
15,900,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Details Sample ...

S.No. Lead_id Tenure Source Premium
1 597 1 year Salaried 9171
2 597 1 year House wife 9171
3 597 1 year child 1 9171
4 605 1 year Salaried 8281.15
5 605 1 year House wife 8281.15
6 605 1 year child 1 8281.15

The output should be like this.---

S.No. Leadid Tenure Source Premium
1 597 1 year Salaried 9171
2 597 1 year House wife 0
3 597 1 year child 1 0
4 605 1 year Salaried 8281.15
5 605 1 year House wife 0
6 605 1 year child 1 0

Note:- I want to show first row value of lead id and other should be zero.

What I have tried:

select dc.premiumAmount as 'Premium', * from tbl_LeadCampaignData_Prospect lcdp with(nolock)
left join tbl_GI_DC_NSTP dc with(nolock) on dc.LeadID=lcdp.LPID
Posted
Updated 19-Jul-16 23:31pm
Comments
Herman<T>.Instance 20-Jul-16 5:14am    
how is the table structure set up?

1 solution

You could try this:
SQL
SELECT z.Sno, z.LeadId, z.[Tenure Source], z.Premium
FROM
(
	SELECT x.Sno, x.LeadId, x.[Tenure Source], x.Premium
	FROM
	(
		SELECT	ROW_Number() Over (ORDER By Sno, LeadId) as Rowno,
				Sno, LeadId, [Tenure Source], dc.premiumAmount as Premium
		FROM	tbl_LeadCampaignData_Prospect lcdp
		LEFT JOIN bl_GI_DC_NSTP dc on dc.LeadID=lcdp.LPID
	) as x
	WHERE x.Rowno = 1

	UNION

	SELECT y.Sno, y.LeadId, y.[Tenure Source], y.Premium
	FROM
	(
		SELECT	ROW_Number() Over (ORDER By Sno, LeadId) as Rowno,
				Sno, LeadId, [Tenure Source], NULL as Premium
		FROM	tbl_LeadCampaignData_Prospect lcdp
	) as y
	WHERE y.Rowno > 1

) as z
ORDER BY z.Sno, z.LeadId
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900