Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

select data field from a table, if exists

I want to select clientrefid from table1 and if it does not return anything I want to select clientrefid from table2 in one store procedure. What should I do?


create procedure select_clientrefid
@clientrefid       varchar(7)

select clientrefid from table1

if return nothing

then select clientrefid from table2
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
create procedure procName (
 @clientrefid varchar(7)
)
as
set nocount on;

if exists(select 1 from table1 where clientrefid = @clientrefid)
begin
   select  clientrefid from table1
end
else
begin
   select clientrefid from table2
end

set nocount off

go