mysql - Stored Procedure Null Value -
i working on assignment , basic function of stored procedure user enter city name , return name of employees , customers particular city. having trouble when run program supplying duplicate names instead of null value in either column. sure there better way join these 2 tables rather 1 long join string drawing blank.
create proc dpcitycontacts @city varchar(20) begin select distinct firstname+', '+lastname employee, custfirstname+', '+custlastname customer #tmp employee e join packingslip ps on e.employeeid = ps.employeeid join shippeditem si on si.packagenumber = ps.packagenumber join custorder co on co.orderid = si.orderid join customer c on c.customerid = co.customerid @city = c.city , @city = e.city , releasedate null group firstname if exists (select 1 #tmp) begin select * #tmp; end else print '“no employees or customers in city of '+ @city end
i think want, not sure cannot test. first of don't want these joins city in same table employee , customer. , in cases want union between select on customer , select on employee. can't join these 2 tables or you'll weird results.
select concat(firstname, ', ', lastname) name, 'employee' type #tmp employee @city = city , releasedate null union select concat(custfirstname, ', ', custlastname) name, 'customer' type customer #tmp @city = city , releasedate null
Comments
Post a Comment