Wednesday, September 7, 2022

CASE Statement on Single column values SQL

 select LEVEL_ID, LEVEL_NAME =  CASE WHEN LEVEL_NAME ='L5' THEN 'L5/L6' 

ELSE LEVEL_NAME END, 

TOTAL_GRANT_SEAT, PERCENTAGE_OF_TOTAL_SEAT from tablename 


select LEVEL_ID, LEVEL_NAME = CASE WHEN LEVEL_NAME ='L5' THEN 'L5/L6' 

ELSE LEVEL_NAME END, 


or


select a.Course_id,'( ' +   case when(c.Course_level_id=5 and Course_Entryon >= '2022-04-01' ) 

then 'L5-L6' when(c.Course_level_id=5 and (Course_Entryon <= '2022-04-01' OR Course_Entryon IS NULL))

then 'L5' else c.level_name end + ') - ' + b.Course_name as Course_name

from TP_REQ_TO_CA_FOR_COURSE a join dbo.MST_COURSE b

on a.Course_ID=b.course_id join MST_COURSE_LEVEL c on

b.Course_level_id=c.Course_level_id and c.Course_level_status=1

where TP_ID='ESDM-HR-TP-000379' 


or


select level_name =case when Course_level_id = 5 then(case when

                   ((select Course_Entryon from MST_COURSE where course_id = @course_id ) >= '2022-04-01') then 'L5-L6'

                when((select Course_Entryon from MST_COURSE where course_id = @course_id) = '')  then 'L5'

                when((select Course_Entryon from MST_COURSE where course_id = @course_id) is NULL)  then 'L5'

                else level_name end) else level_name end from dbo.MST_COURSE_LEVEL

                where Course_level_id = (select distinct(Course_level_id) from MST_COURSE where course_id = @course_id)



or


SELECT CR.Max_course_fee, CR.course_id,CR.Course_Code,CR.Course_name,isnull(CR.Accreditation_fees,0) as Accreditation_fees,CL.Course_level_id,case when(CR.Course_level_id=5 and Course_Entryon >= '2022-04-01' ) 

then 'L5-L6' when(CR.Course_level_id=5 and (Course_Entryon <= '2022-04-01' OR Course_Entryon IS NULL))

then 'L5' else level_name end as level_name


,IV.Industry_vertical_id,IV.Industry_vertical_name,CA.Certifying_agency_id,CA.Certifying_agency_name,isnull(CA.Processing_fees,0) as Processing_fees,isnull(CA.Inspection_fees,0)as Inspection_fees  FROM dbo.MST_COURSE AS CR INNER JOIN dbo.MST_COURSE_LEVEL AS CL ON CR.Course_level_id = CL.Course_level_id INNER JOIN dbo.MST_INDUSTRY_VERTICAL AS IV ON CR.Industry_vertical_id=IV.Industry_vertical_id INNER JOIN dbo.MST_CERTIFYING_AGENCY AS CA ON CR.Certifying_agency_id=CA.Certifying_agency_id WHERE CR.Certifying_agency_id in(" + CertifyingAgencyID + ") AND CR.course_tp_status=1  AND CR.course_id NOT IN(SELECT Course_id FROM [dbo].[TP_REQ_TO_CA_FOR_COURSE]

No comments:

Post a Comment