Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 fetching records from first table and if not found

Author  Topic 

irfi
Starting Member

2 Posts

Posted - 2012-05-29 : 12:11:31
Hi everyone!
This is my first post and i would appreciate if someone could help me with the SQL Query to look for records in first table and then if not found look in second table and populate the fields on my windows form. In case records not found in both tables then i will display records not found.

"Select a.id, a.name, b.dept from emp_table1 a, dept b where a.id = b.id and a.id=" & Text1.text"

"Select a.id, a.name, b.dept from emp_table2 a, dept b where a.id = b.id and a.id=" & Text1.text"

Thanks and Cheers!
IrFi

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-29 : 12:19:41
quote:
Originally posted by irfi

Hi everyone!
This is my first post and i would appreciate if someone could help me with the SQL Query to look for records in first table and then if not found look in second table and populate the fields on my windows form. In case records not found in both tables then i will display records not found.

"Select a.id, a.name, b.dept from emp_table1 a, dept b where a.id = b.id and a.id=" & Text1.text"

"Select a.id, a.name, b.dept from emp_table2 a, dept b where a.id = b.id and a.id=" & Text1.text"

Thanks and Cheers!
IrFi




"SELECT a.id, a.name, b.dept
FROM (SELECT id, name from emp_table1
union
Select id, name from emp_table2
)a
dept b
where a.id = b.id and a.id=" & Text1.text"




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

irfi
Starting Member

2 Posts

Posted - 2012-05-31 : 05:35:53
Thanks a lot visakh16 for your reply. It worked like a charm.

regards,
Irfi
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-31 : 16:09:05
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -