yperea
Starting Member
1 Post |
Posted - 2008-06-30 : 11:52:16
|
I am new to SQL and need assistance working with the database that has multiple tables. I need to join several tables but I need to make sure that if column(phone number) is blank to omit. Not sure how to handle this.I also need to join another table if donor_id has multiple visits then they would have a preferred status. Can you please help?? I currently have two separate queries and would like to combine.Query1SELECT [donor_id] ,isnull ([salutation],'')as salutation ,[first_name] ,isnull ([middle_initial],'') as middle_initial ,[last_name] ,isnull ([suffix],'') as suffix ,convert (varchar(12),[birthdate],101) as birthdate ,isnull ([blood_type],'') as blood_type ,[gender] ,[address1] ,isnull ([address2],'') as address2 ,[city] ,[state] ,[zip] ,isnull ([email],'') as email ,isnull ([hphone],'') as hphone ,isnull ([hphone_ext],'') as hphone_ext ,isnull ([wphone],'') as wphone ,isnull ([wphone_ext],'') as wphone_ext ,isnull ([mphone],'') as mphone ,isnull ([mphone_ext],'') as mphone_ext ,convert (varchar(12),[next_callback_date],101) as next_callback_date ,isnull ([last_donor_note],'') as last_donor_note ,convert(varchar(12),[wb_elig],101) as wb_elig ,convert(varchar(12),[pl_elig],101) as pl_elig ,convert(varchar(12),[ps_elig],101) as ps_elig ,isnull ([program_level],'') as program_level ,isnull ([outstanding_points],'') as outstanding_points ,convert(varchar(12),[last_visit_datetime],101) as last_visit_datetime ,isnull ([last_visit_donation_type],'') as last_visit_donation_type ,isnull ([last_visit_status],'') as last_visit_status ,isnull ([last_visit_type],'') as last_visit_type ,isnull ([last_visit_location_code],'') as last_visit_location_code ,isnull ([last_visit_location],'') as last_visit_location ,isnull ([last_visit_search_code],'') as last_visit_search_code ,isnull ([last_visit_cholesterol],'') as last_visit_cholesterol ,convert(varchar(12),[next_appt_datetime],101) as next_appt_datetime ,isnull ([next_appt_type],'') as next_appt_type ,isnull ([next_appt_location_code],'') as next_appt_location_code ,isnull ([next_appt_location],'') as next_appt_location ,isnull ([next_appt_donation_type],'') as next_appt_donation_type ,isnull ([suppression_group_code],'') as suppression_group_code ,isnull ([list_type],'') as list_type ,isnull ([list_name],'') as list_name FROM [eDonor].[dbo].[TBL_ELIGIBLEDONORS]where zip in('89408','89431','89432','89433','89434','89435','89436','89438','89439','89501','89502','89503','89504','89505','89506','89507','89508','89509','89510','89511','89512','89513','89515','89520','89521','89523','89533','89460','89711','89712','89713','89714','89533','89438','89505','89508') and last_visit_datetime between '06/01/2006' and '06/01/2008'and last_visit_donation_type in ('Whole Blood','Double Red Cell')order by last_visit_location_codeQuery 2select tbl_eligibledonors.donor_id ,tbl_eligibledonors.first_Name ,tbl_eligibledonors.hPhone from tbl_eligibledonors left join tbl_visits ontbl_eligibledonors.donor_id = tbl_visits.donor_idgroup by tbl_eligibledonors.donor_id, tbl_eligibledonors.first_Name, tbl_eligibledonors.hPhonehaving count(*) >= 5Thank you, Yvonne |
|