SQL Join Example – if null (ifnull)

A useful SQL join example where the if null (ifnull) function is used.

 

insert into lpt_register_appends_3
(  name,
   add_line1,
   add_line2,
   add_line3,
   add_line4,
   age,
   salary,
   company_id,
   company_address,
   fav_band,
   fav_color,
   fav_team,
   fav_ice_cream,
   shoe_size,
   eye_color,
   hair_color,
   hair_style,
   fav_food,
   tea_coffee,
   description,
   date
)
SELECT
ifnull(eit_one.name,”),
ifnull(eit_one.addr1,”),
ifnull(eit_one.addr2,”),
ifnull(eit_one.addr3,”),
ifnull(eit_one.addr4,”),
ifnull(eit_two.age,null),
ifnull(eit_two.salary,null),
ifnull(eit_two.building_id,null),
ifnull(eit_two.address_point_id,null),
‘NF’,
‘NF_’+ifnull(eit_two.key,’427’),
eit_two.rank,
eit_two.quality,
‘111222333w’,
‘1’,
‘1’,
null,
null,
‘0’,
‘This is the description’,
‘20130305.00000000’
FROM employee_info_table_one eit_one
left join employee_info_table_two eit_two on eit_one.id = eit_two.id

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: