Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My query as follows

SQL
select b.cmn_minor_code as Course,c.cmn_minor_desc as Eligbility,convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
convert(char(12),b.cbm_batch_end_dt,106) as Enddt from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b,CO_MINOR_MASTER as c
where a.course = b.cmn_minor_code and a.Rank = 'CHENGR' and b.cbm_active <> 'd'
and b.cmn_minor_code = c.cmn_minor_code
and a.Active <> 'd' and b.cbm_batch_start_dt between  '2015-08-01 00:00:00.000' and 
 '2015-09-30 00:00:00.000'


when i run the above query output as follows

Course         Eligbility         Startdt         Enddt
REO         CHIEF ENGINEER       10 Aug 2015     21 Aug 2015
REO         CHIEF ENGINEER       24 Aug 2015     04 Sep 2015
REO         CHIEF ENGINEER       14 Dec 2015     25 Dec 2015


But i want the output as follows

Course      Eligbility        Startdt             Enddt
REO        CHIE ENGINEER      10 Aug 2015      21 Aug 2015
                              24 Aug 2015       04 Sep 2015
                             14 Dec 2015       25 Dec 2015


for that how to avoid the Course and Eligbility in repeation using my above query
please help me.

What I have tried:

Repetition of what is above.

My query as follows

select b.cmn_minor_code as Course,c.cmn_minor_desc as Eligbility,convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
convert(char(12),b.cbm_batch_end_dt,106) as Enddt from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b,CO_MINOR_MASTER as c
where a.course = b.cmn_minor_code and a.Rank = 'CHENGR' and b.cbm_active <> 'd'
and b.cmn_minor_code = c.cmn_minor_code
and a.Active <> 'd' and b.cbm_batch_start_dt between '2015-08-01 00:00:00.000' and
'2015-09-30 00:00:00.000'

when i run the above query output as follows

Course Eligbility Startdt Enddt
REO CHIEF ENGINEER 10 Aug 2015 21 Aug 2015
REO CHIEF ENGINEER 24 Aug 2015 04 Sep 2015
REO CHIEF ENGINEER 14 Dec 2015 25 Dec 2015

But i want the output as follows

Course Eligbility Startdt Enddt
REO CHIE ENGINEER 10 Aug 2015 21 Aug 2015
24 Aug 2015 04 Sep 2015
14 Dec 2015 25 Dec 2015

for that how to avoid the Course and Eligbility in repeation using my above query
please help me.
Posted
Updated 16-Feb-16 17:49pm
v2

What you want is more or less user interface's job. Once you have the data, make sure you use proper UI control/tool that can display it the way you want.
 
Share this answer
 
I strongly suggest what has been mentioned on the Solution 1. That I also feel this is the responsibility of the UI (Crystal Reports, Excel etc...) to decide how the details should be displayed.

But if the requirement to have it on the database side, you also can use a similar method what's shown below.

SQL
CREATE TABLE #TestTable(
	Course			VARCHAR(10)		NOT NULL
	,Eligibility	VARCHAR(20)		NOT NULL
	,StartDate		SMALLDATETIME	NOT NULL
	,EndDate		SMALLDATETIME	NOT NULL
)

INSERT INTO #TestTable
        (Course
        ,Eligibility
        ,StartDate
        ,EndDate
        )
VALUES	
('REO','CHIEF ENGINEER','10-Aug-2015','21-Aug-2015')
,('REO','CHIEF ENGINEER','24-Aug-2015','04-Sep-2015')
,('REO','CHIEF ENGINEER','14-Dec-2015','25-Dec-2015')
,('REO','ENGINEER','26-Dec-2015','28-Dec-2015')
,('REO','ENGINEER','29-Dec-2015','31-Dec-2015')



SELECT 
    IIF(A.Sort_ID<>1,'',A.Course) AS Course
	,IIF(A.Sort_ID<>1,'',A.Eligibility) AS Eligibility
    ,A.StartDate
    ,A.EndDate
FROM(
	SELECT  
		ROW_NUMBER() OVER (PARTITION BY Src.Course,Src.Eligibility ORDER BY Src.Course,Src.Eligibility) AS Sort_ID
		,DENSE_RANK() OVER(ORDER BY Src.Course,Src.Eligibility) AS Rank_ID
		
		,Src.*
	FROM #TestTable AS Src
) AS A
ORDER BY A.Rank_ID,A.Sort_ID
 
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