?
Solved

how can I use IF in my query?

Posted on 2010-01-13
4
Medium Priority
?
147 Views
Last Modified: 2012-05-08
Hello guys

I have a problem and I don't know how to solve this.

I want to get all rows when TFAT not in ('E','X','H','T') and (B.OutrasSaidas <> 'O' OR B.OutrasSaidas IS NULL)

but there is a case where I have some rows that TFAT is = '1' but OutrasSaidas is also = 'O'
when I have this, I need to discard this option (outrassaidas) to get the value .
Is there any way to do that?
thanks
SELECT convert(char(10),B.NFI_DEMI,103) AS EMISSAO, SUM(A.INF_TOTA) AS FAT_NF,
       0 AS QTD_NF,SUM(isnull(B.NFI_VICS,0))AS SUBTRIBUTARIA INTO #TMP_CONSVENDAS FROM SIAINFI A (NOLOCK), SIANFIS B (NOLOCK)
WHERE A.INF_FORN in ('JOAL','NORSCOT','FICUS','LAPLISA','LAPLISA2','ROYAL OPERA','PARNASSA','ZARD','ROS','DAIWA')
  AND A.EMPRESA  in ('CARAJAS','HIDRAU')
  AND B.NFI_CODI=A.INF_CODI
  AND B.EMPRESA=A.EMPRESA
  AND B.NFI_CLIE NOT IN ('1','2042','4611','8910','9286','27289')
  AND CONVERT(Char(10), B.NFI_DEMI, 112) >= '20100101'
  AND CONVERT(Char(10), B.NFI_DEMI, 112) <= '20100112'
  AND (B.NFI_CANC      = 'N')
  AND (B.NFI_TFAT NOT IN ('E','X','H','T'))
  AND (B.NFI_FATESPE  <> 'S')
  AND (B.OutrasSaidas <> 'O' OR B.OutrasSaidas IS NULL)
  AND (B.NFI_NFIS IS NOT NULL)
  GROUP BY convert(char(10),B.NFI_DEMI,103)
  ORDER BY EMISSAO

Open in new window

0
Comment
Question by:hidrau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
rajvja earned 2000 total points
ID: 26302749
use
case
   when condition
   then
  value
  when condition
  then value
else
   value
end as OutputFldName
0
 
LVL 1

Author Comment

by:hidrau
ID: 26302769
friend,
 could you give me an example how I could do that in this query?
0
 
LVL 11

Assisted Solution

by:rajvja
rajvja earned 2000 total points
ID: 26302852
case is helpful in select query field list

select case when fld=value then newvalue end from tablename

like that
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 31676607
THANKS
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question