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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -