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 2005 Forums
 Transact-SQL (2005)
 IF in Where Clause ?

Author  Topic 

Core
Starting Member

15 Posts

Posted - 2007-07-17 : 13:53:25

Hi All, before all, AMAZING FORUM!!! OLD Reader.. :)

I start with a quick (i think) doubt, imagine this simple QUERY :

SELECT Mov_Custos.*,
Tbl_Tipo_Artigo.tipo_artigo,
Tbl_Funcionario.nome_func,
Tbl_Tx_Iva.taxa
FROM Mov_Custos INNER JOIN
Tbl_Tipo_Artigo ON Mov_Custos.id_tipo_artigo = Tbl_Tipo_Artigo.id_tipo_artigo INNER JOIN
Tbl_Funcionario ON Mov_Custos.id_func = Tbl_Funcionario.id_func INNER JOIN
Tbl_Tx_Iva ON Mov_Custos.id_iva = Tbl_Tx_Iva.id_iva


But if Mov_Custos.id_func is null or '' the hole row don't appear because the WHERE part in bold.
What can i do to ignore the bold part, or something else that help..

I cainda need a urgent help :(

THANKS FOR ANY HELP,
Hugo Core

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-17 : 13:54:22
use a left join.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Core
Starting Member

15 Posts

Posted - 2007-07-17 : 14:03:24
OMG! Thats was fast :P So many Thanks..

Reference:

"The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-18 : 03:41:56
Also Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -