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
 SQL Server Administration (2005)
 Constraint Expression in SQL Server 2005 IDE

Author  Topic 

hismightiness
Posting Yak Master

164 Posts

Posted - 2007-03-20 : 12:35:50
I was trying to enter a constraint expression into the dialog box. I have three fields of the data type "bit". I want to make sure that of the three, only one equals "1". Using the documentation I found in Books Online, I attempted to use the following expression, but it would not validate.

(expert == 1 && supplier == 0 && employee == 0) || (expert == 0 && supplier == 1 && employee == 0) || (expert == 0 && supplier == 0 && employee == 1)

Can someone please assist me in getting this corrected?

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://www.servicerank.com/

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-20 : 15:40:12
You're using C# (or C++, or Java) syntax, not Transact-SQL syntax, you want to use this,

(expert = 1 AND supplier = 0 AND employee = 0) OR (expert = 0 AND supplier = 1 AND employee = 0) OR (expert = 0 AND supplier = 0 AND employee = 1)
Go to Top of Page

hismightiness
Posting Yak Master

164 Posts

Posted - 2007-03-20 : 15:47:09
Hmmm... I thought the syntax was odd. The documentation didn't specify the language. I just checked again. :(

Thank you so much for your help. It worked!

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://www.servicerank.com/
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-03-20 : 16:00:57
You could also do it this way:
convert(int,expert)+convert(int,supplier)+convert(int,employee) = 1


CODO ERGO SUM
Go to Top of Page

hismightiness
Posting Yak Master

164 Posts

Posted - 2007-03-20 : 16:10:40
Nice! I like that way much better!

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://www.servicerank.com/
Go to Top of Page
   

- Advertisement -