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)
 relationship using NULL values

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-01-17 : 10:59:36
I have a main table with some columns and their relationship everything works fine.

But i have one column that i need to make a relationship with other table,but this columns can be ZEROS or NULL , in this case realationship fails.

the question is: how can i make a relationship only if the column is different from NULL or ZEROS?

tks
Carlos Lages
Rio de Janeiro

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-17 : 11:04:44
join tbl t2
on t1.col = t2.col
and t2.col <> 0

null will already be catered for as it will never be included in the join.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2004-01-17 : 16:28:42
I am talking about relationship using MS-DIAGRAM.

how to make a relationship in Diagram if one column is NULL?

Diagram only make this if all keys is true.

tks

Carlos Lages
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-01-18 : 19:17:45
MS-DIAGRAM? Is that the name of the diagram builder in SQL Server Enterprise Manager? So what you're looking to create is a Foreign Key Constraint? Then every non-Null value in the primary table has to match a value in the foreign table. If there are NULLs in the primary table, then there is nothing for it to check in the destination, and that should be just fine when you create the constraint. As for Zeroes, you'll need a zero key in the foreign table or it will fail.

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page
   

- Advertisement -