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)
 SQL select issue

Author  Topic 

gio123bg
Starting Member

5 Posts

Posted - 2009-06-15 : 04:30:58
Hi,
I wish to know how I can display a negative or positive value field in sql query. More exactly if a fied fx of a table contain N I need to view le fied f1 in negative form

Example
SELECT f1
from Tab1
Where ...

but if fx = N --> -f1
otherwise +f1

How can I solve this problem?
many thanks in advance for your kind support.
Regards,

Giovanni

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-15 : 04:59:47
SELECT fx, -fx, ABS(fx), -ABS(fx)
FROM Table1


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

gio123bg
Starting Member

5 Posts

Posted - 2009-06-15 : 05:27:52
Many thanks for the quick replay and for the suggestion.

But suppose to display after a query:

|------|
| f1 |
|------|
| +5 |
| -4 |
|------|
In my table T1 I have f1 always positive and e column Fx where I can find N or H, for example and if I find H, I disppaly +<value F1> or if I find H I display -<value F1>. More exatly, I need to introduce a condition in my select, if this is possible.
How can I write the select?
Thanks.
Regards,

Giovanni
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-15 : 05:33:24
SELECT CASE when fx = 'n' then f1 else -f1 end as newf1
FROM Table1


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

gio123bg
Starting Member

5 Posts

Posted - 2009-06-15 : 09:32:49
Thanks a lot!
Go to Top of Page
   

- Advertisement -