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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 select if null
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

macuser
Starting Member

Poland
2 Posts

Posted - 12/05/2013 :  01:55:15  Show Profile  Reply with Quote
I have select:

select *
from serviceorders as zlecenie
--join orderitems as linijki on linijki.serviceorder_id = zlecenie.id
where zlecenie.id = 38

table: serviceorders(headers) is joined to orderitems(items).
In above case(id=38) - I have serviceorder, but i don't have orderitems(in remaining case data are present in both tables).
If I ask only for serviceorders=38 - I receive result, but if I ask about orderitems too I will receive empty result(but I need data from serviceorders(such Name, adress).

How can I ask about data from serviceorders in case when orderitems is empty but I need data from serviceorders(such Name, adress)?

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 12/05/2013 :  02:08:24  Show Profile  Reply with Quote

select *
from serviceorders as zlecenie
left outer join orderitems as linijki 
on linijki.serviceorder_id = zlecenie.id
where zlecenie.id = 38


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

macuser
Starting Member

Poland
2 Posts

Posted - 12/05/2013 :  02:54:21  Show Profile  Reply with Quote
many thanks, it works!
Go to Top of Page
  Previous Topic Topic Next 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