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)
 Boolean Logic in 2005

Author  Topic 

dav1djed
Starting Member

10 Posts

Posted - 2007-04-01 : 08:58:00
I have a problem. I am trying to test complex boolean logic but the only thing I have found is a declare statement, but TSQL does not recognize ABSOLUTE VALUE. Is there a way to write to the database to check something like IF ABS(5) > 0 or or IF ABS(6) + ABS(-8) = 6 + (-8)?

dav1djed
Starting Member

10 Posts

Posted - 2007-04-01 : 09:13:22
This actually may work

select 'True' from [Table name with single row]
having ABS(6) > 0
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-01 : 09:18:52
SELECT 'True' FROM Table1
WHERE Col1 < 6 OR Col1 > 6

might give you better performance if index is present on Col1.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

dav1djed
Starting Member

10 Posts

Posted - 2007-04-01 : 09:24:35
quote:
Originally posted by Peso

SELECT 'True' FROM Table1
WHERE Col1 < 6 OR Col1 > 6

might give you better performance if index is present on Col1.


Peter Larsson
Helsingborg, Sweden



Peter thanks but the Boolean logic is actually built in a VARCHAR field which is pulled in dynamically. Sometimes it is >, <, or =.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-01 : 09:34:27
I didn't know that. That is a new piece of information.
Do you think it is fair to only tell a part of your problem and having us to guess what you want?

Post again what you are trying to achieve, with full sample data and your expected output.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-04-02 : 07:48:34
quote:
Originally posted by dav1djed
Peter thanks but the Boolean logic is actually built in a VARCHAR field which is pulled in dynamically. Sometimes it is >, <, or =.

I believe you are looking at CLR routines then.
http://pluralsight.com/blogs/dan/archive/2006/07/27/32597.aspx
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-02 : 14:31:03
quote:
Originally posted by dav1djed

but TSQL does not recognize ABSOLUTE VALUE.



Since when?

SELECT ABS(-6)

Absolutely works



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-04-02 : 16:10:20
quote:
Originally posted by X002548

quote:
Originally posted by dav1djed

but TSQL does not recognize ABSOLUTE VALUE.



Since when?

SELECT ABS(-6)

Absolutely works



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam





The principal problem is the principal did not state the problem
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-04-03 : 02:07:39
I "absolutely" agree...

--Jeff Moden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-03 : 02:43:32
1) Two OR's are not allowed.
2) IF's are for procedural checks. You should use AND / OR instead.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -