Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select people who didn't renew their license registration

$
0
0

Say i have to generate a report to show the people who didn't renew their license registration , renew of license registration must be every year , i want to select by the date of last renew which might be before more than 2 or 3 years.

I want to except the people who renew their license this year ...

thanks in advance..


SELECT DISTINCT  ent.entre_name ,activity_desc  , Firm_name , neighbor, street_name , unit_neighbor , 
	ISNULL(CONCAT(ISNULL(front_panel_height,0) ,'  X  ', ISNULL(front_panel_width,0)),'non') AS 'front_panel',
	ISNULL(CONCAT(ISNULL(side_panel_height,0) ,'  X  ', ISNULL(side_panel_width,0)),'non') AS 'side_bullet',
	CONVERT(VARCHAR(10),registering_date,111) AS 'registering_date', 
	CONVERT(VARCHAR(10),expired_license_date,111) AS 'expired_license_date' , 
	ISNULL(charge_differs,0) AS 'charge_differs'  , MAX(fin_amt) AS 'fin_amt', licop.operation_no 

FROM entrepreneur AS ent
    INNER JOIN Firm_info AS firm
        ON ent.entre_ID = firm.entre_ID
    INNER JOIN Section AS sec
        ON firm.Section_ID = sec.Section_id
    INNER JOIN license AS lic
        ON firm.firm_no = lic.firm_no
    INNER JOIN license_operations AS licop
        ON lic.license_serial = licop.license_serial
	INNER JOIN license_charges AS licha
       ON licop.operation_no = licha.operation_no
    INNER JOIN charges AS cha
	ON cha.charge_Id = licha.charge_id 
    INNER JOIN activities AS acts
	ON firm.activity_type = acts.activity_no

 WHERE sec.Section_id = @section_no 
   AND YEAR(SYSDATETIME()) > ( SELECT YEAR(MAX(expired_license_date)) 
     FROM entrepreneur AS inner_ent	INNER JOIN Firm_info AS inner_firm 
	 ON inner_ent.entre_ID = inner_firm.entre_ID
	 INNER JOIN Section AS inner_sec
	 ON inner_firm.Section_ID = inner_sec.Section_id
	 INNER JOIN license AS inner_lic
	 ON inner_firm.firm_no = inner_lic.firm_no
	 INNER JOIN license_operations AS inner_licop
	 ON inner_lic.license_serial = inner_licop.license_serial
	WHERE sec.Section_id = @section_no
	AND YEAR(SYSDATETIME()) > YEAR(expired_license_date)
											 )		   
GROUP BY ent.entre_name , activity_desc  , Firm_name , neighbor,
	 street_name , unit_neighbor , front_panel_height,    front_panel_width, side_panel_height,
		   side_panel_width, registering_date , expired_license_date , charge_differs , licop.operation_no

HAVING YEAR(SYSDATETIME()) > YEAR(MAX(expired_license_date)) 



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>