File: /www/exchange2/sql/archive/2016-01-14-271.sql
ALTER TABLE `user_login` CHANGE COLUMN `user_id` `user_id` SMALLINT(20) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;
INSERT INTO temp_registration (temp_reg_id,username,password,register_type,organization_name,organization_address_id,user_type,status,permission,created_at,doj)
SELECT NULL, LEFT(organisation_name,10),LEFT(organisation_name,10),0, organisation_name, organisation_address_id,7,4,1,NOW(),NOW()
FROM organisation_details
WHERE type=6;
UPDATE `temp_registration`
SET `ref_id` = (CONCAT(DATE_FORMAT(doj,'%Y%m%d'), '000000') + temp_reg_id)
WHERE ref_id IS NULL AND user_type=7;
INSERT INTO user_login (user_id,username,user_password,user_type,user_status)
SELECT NULL,username,password,user_type,1
FROM temp_registration
WHERE user_type=7;
UPDATE temp_registration
LEFT JOIN user_login ON user_login.user_type = temp_registration.user_type AND temp_registration.username = user_login.username AND temp_registration.password = user_login.user_password
SET temp_registration.user_id = user_login.user_id
WHERE temp_registration.user_type=7;
UPDATE organisation_details
LEFT JOIN temp_registration ON temp_registration.organization_address_id = organisation_details.organisation_address_id
SET organisation_details.user_id = temp_registration.user_id
WHERE temp_registration.user_type=7;