SQL Server Display only lines with all values not equal to 0

olivier

In SQL server 2008r2, i want to display only lines where some columns are not equal to '0'

For example: I want to display only lines where columns 2 and 3 are <> '0'

line 1 : val1 = 2, val2 = 2, val3 = 0

line 2 : val1 = 1, val2 = 0, val3 = 0

line 3 : val1 = 0, val2 = 0, val3 = 5

line 4 : val1 = 10, val2 = 0, val3 = 3

line 5 : val1 = 0, val2 = 0, val3 = 0

In this example, i want to display lines 1,3,4 but not lines 2 and 5 because both columns 2 & 3 are = '0'

I tried with NOT EXISTS but it didn't work.

EDIT : Hi, i think it's difficult for me to explain clearly what i want, i put you my definitive request, perhaps you could define my need ^^ :

select * from CONSULTANT inner join REPORTINGCONSULTANT on CONSULTANT.ID = REPORTINGCONSULTANT.FK_CONSULTANT where [CONSULTANT].[ISDESACTIVE] = '0' and [CONSULTANT].[ISSUPPRIME] = '0' and [CONSULTANT].[INITIALES] not like 'IL%' and [REPORTINGCONSULTANT].[DATEDEBUT] >= '02/06/2014' and [REPORTINGCONSULTANT].[NBCANDIDATSPUSH] <> '0' and [REPORTINGCONSULTANT].[NBCVENVOYESURPOSTE] <> '0' and [REPORTINGCONSULTANT].[NBRDVPROSPECTS] <> '0' and [REPORTINGCONSULTANT].[NBRDVCLIENTS] <> '0' and [REPORTINGCONSULTANT].NBPROSPECTSRENCONTRES] <> '0' and [REPORTINGCONSULTANT].[NBPROSPECTSRENCONTRESBINOME] <> '0' and [REPORTINGCONSULTANT].[NBCLIENTSRENCONTRES] <> '0' and [REPORTINGCONSULTANT].[NBCLIENTSRENCONTRESBINOME] <> '0' 

When i run only the begining (stop after the date), it counts me 1700 results If i run the rest, it counts me 0 result

but i can find lines where all lines are true

Jaugar Chang

Count the number of values not equal to 0 by sign(abs(x)).

SELECT t.* 
FROM dbo.TableName t
WHERE sign(abs(val1))+sign(abs(val2))+sign(abs(val3)) >1

It implements the requirement of :

display only lines where some columns are not equal to '0'

If "some" means val2 and val3, it could be:

SELECT t.* 
FROM dbo.TableName t
WHERE sign(abs(val2))+sign(abs(val3)) >0

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to display all the days of a month in SQL Server 2008?

분류에서Dev

Remove columns from SQL output where all values are 0

분류에서Dev

Select distinct rows where all values in a column are the same SQL Server

분류에서Dev

Only show the lines that are in all textfiles at least once

분류에서Dev

Subtract values only if all are numbers

분류에서Dev

SQL Query for Group by with two sorting values and count the equal values

분류에서Dev

CFDump of query column does not display all values

분류에서Dev

update time only in sql server

분류에서Dev

SQL Join left, group by to get ID is equal to a specific only

분류에서Dev

SQL query all ID's not equal to session ID

분류에서Dev

SQL server not returning all rows

분류에서Dev

SQL Server : 조건부 where 절 (Equal) OR (LessThan 또는 Equal)

분류에서Dev

How to use awk to print all lines whose third column value equals "0" instead of 0?

분류에서Dev

SQL Server 2008 : how to remove char(0)

분류에서Dev

SQL Server의 SUM (Time (0))

분류에서Dev

SQL Server의 SUM (Time (0))

분류에서Dev

SQL Server : database connection with textbox values

분류에서Dev

SQL Server 2012 Pivot Dynamic with Values?

분류에서Dev

add values depending on a condition sql-server

분류에서Dev

Remove duplicate values in a cell SQL Server

분류에서Dev

Multiply column values in SQL, then add all the values - Laravel 4

분류에서Dev

A method that is supposed to print all values of an array only returns nulls.

분류에서Dev

display only selected column from SQL using PHP

분류에서Dev

Trying to access a SQL Server database to display a single row in c#

분류에서Dev

Displaying lines with diffent values

분류에서Dev

All Lines are Dotted!

분류에서Dev

What is the SQL query in Access to replace all column values with one of it's values, which depends on values of other attributes?

분류에서Dev

Is it possible to have a SQL Server database with case sensitive data only

분류에서Dev

Include 0 when using count() SQL Server Left Join not working

Related 관련 기사

  1. 1

    How to display all the days of a month in SQL Server 2008?

  2. 2

    Remove columns from SQL output where all values are 0

  3. 3

    Select distinct rows where all values in a column are the same SQL Server

  4. 4

    Only show the lines that are in all textfiles at least once

  5. 5

    Subtract values only if all are numbers

  6. 6

    SQL Query for Group by with two sorting values and count the equal values

  7. 7

    CFDump of query column does not display all values

  8. 8

    update time only in sql server

  9. 9

    SQL Join left, group by to get ID is equal to a specific only

  10. 10

    SQL query all ID's not equal to session ID

  11. 11

    SQL server not returning all rows

  12. 12

    SQL Server : 조건부 where 절 (Equal) OR (LessThan 또는 Equal)

  13. 13

    How to use awk to print all lines whose third column value equals "0" instead of 0?

  14. 14

    SQL Server 2008 : how to remove char(0)

  15. 15

    SQL Server의 SUM (Time (0))

  16. 16

    SQL Server의 SUM (Time (0))

  17. 17

    SQL Server : database connection with textbox values

  18. 18

    SQL Server 2012 Pivot Dynamic with Values?

  19. 19

    add values depending on a condition sql-server

  20. 20

    Remove duplicate values in a cell SQL Server

  21. 21

    Multiply column values in SQL, then add all the values - Laravel 4

  22. 22

    A method that is supposed to print all values of an array only returns nulls.

  23. 23

    display only selected column from SQL using PHP

  24. 24

    Trying to access a SQL Server database to display a single row in c#

  25. 25

    Displaying lines with diffent values

  26. 26

    All Lines are Dotted!

  27. 27

    What is the SQL query in Access to replace all column values with one of it's values, which depends on values of other attributes?

  28. 28

    Is it possible to have a SQL Server database with case sensitive data only

  29. 29

    Include 0 when using count() SQL Server Left Join not working

뜨겁다태그

보관