| Author |
Topic |
|
devisetti
Starting Member
30 Posts |
Posted - 2008-05-15 : 00:10:00
|
| I have the following table with sample data like thisREC1 REC2----------------111 666222 777333 888000 766000 866456 000678 000I want a query with results that should ignore zeros in the two columns.Desired output:REC1 REC2----------------111 666222 777333 888Thanks |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-05-15 : 00:21:55
|
| SELECT TOP 3 REC1,REC2 FROM <TABLENAME> |
 |
|
|
devisetti
Starting Member
30 Posts |
Posted - 2008-05-15 : 00:25:04
|
| I have large volume of data. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-05-15 : 00:28:29
|
| TRY THIS ALSO IF COL1 AND COL2 ARE OF INT TYPEDECLARE @TEST TABLE ( COL1 INT, COL2 INT)INSERT INTO @TEST SELECT 111,343 UNION ALLSELECT 365,675 UNION ALLSELECT 000,3453 UNION ALLSELECT 895,000 UNION ALLSELECT 000,000SELECT * FROM @TEST WHERE COL1 <> 0 AND COL2 <> 0 |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-05-15 : 00:44:04
|
| hitry thisdeclare @tb table(rec1 int,rec2 int)insert @tb select 111,666union all select 222,777union all select 333,888union all select 000,766union all select 000,866union all select 456,000union all select 678,000select * from @tb select rec1,rec2 from @tb where rec1 !=0 and rec2 !=0ok tanx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-15 : 01:21:47
|
| SELECT REC1,REC2 FROM YourTable Where (CAST(REC1 as int) + CAST(REC2 AS int))> 0 |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-05-15 : 02:10:02
|
| hi visakh ur query is not giving expected result...i think it can be changed as followsSELECT REC1,REC2 FROM @tb Where CAST(REC1 as int)>0 and CAST(REC2 AS int)> 0oktanx.. |
 |
|
|
devils3cups
Starting Member
23 Posts |
Posted - 2008-05-15 : 11:59:13
|
| Whats wrong withSelect * from tablewhere rec1 != 000 or rec2 != 000; |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-05-16 : 05:25:33
|
quote: Originally posted by devils3cups Whats wrong withSelect * from tablewhere rec1 != 000 or rec2 != 000;
hino it wont give ur resultuse below onebcos u want to exclude 000 value from both columnsthen only proper selection will be doneSelect * from @tbwhere rec1 != 000 and rec2 != 000hopes it will clarify uok |
 |
|
|
devils3cups
Starting Member
23 Posts |
Posted - 2008-05-16 : 09:51:05
|
quote: Originally posted by soorajtnpki
quote: Originally posted by devils3cups Whats wrong withSelect * from tablewhere rec1 != 000 or rec2 != 000;
hino it wont give ur resultuse below onebcos u want to exclude 000 value from both columnsthen only proper selection will be doneSelect * from @tbwhere rec1 != 000 and rec2 != 000hopes it will clarify uok
Stupid mistake. I'm trying to get involved in the forum |
 |
|
|
|