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 2012 Forums
 Transact-SQL (2012)
 select if null

Author  Topic 

macuser
Starting Member

2 Posts

Posted - 2013-12-05 : 01:55:15
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

52326 Posts

Posted - 2013-12-05 : 02:08:24
[code]
select *
from serviceorders as zlecenie
left outer join orderitems as linijki
on linijki.serviceorder_id = zlecenie.id
where zlecenie.id = 38
[/code]

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

macuser
Starting Member

2 Posts

Posted - 2013-12-05 : 02:54:21
many thanks, it works!
Go to Top of Page
   

- Advertisement -