Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

serach for records in each table and o/p the result

$
0
0
 

Query is not searching for other tables for more records, it is searching for only one table and giving the result

Expected o/p :

EmpID empname salary
77     brown  100
EID ename dept
2  Keshav HR

Query Used :

create table #temp (CRMguid Nvarchar(50))

insert into #temp(crmguid)  values  (77),(2),(2)
Go

if exists (select COUNT(1) from employeinfo.dbo.emp where empid in ( select * from #temp))
begin
(select  * from employeinfo.dbo.emp where empid in  ( select * from #temp))
end


else if exists (select count(1) from employeinfo.dbo.emp1 where eid in ( select * from #temp))
begin
select  * from emp1 where eid in ( select * from #temp)
End

 
else if exists (select count(1) from employeinfo.dbo.emp1 where eid in ( select * from #temp))
 begin
select * from employeinfo.dbo.employee where id in ( select * from #temp)
end

 

 


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>