SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 fetching records from first table and if not found
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

irfi
Starting Member

2 Posts

Posted - 05/29/2012 :  12:11:31  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 05/29/2012 :  12:19:41  Show Profile  Reply with Quote
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 - 05/31/2012 :  05:35:53  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 05/31/2012 :  16:09:05  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000