June 27, 2014 at 10:20 am
Table : Consumer
KNO Amount
8789 10
8896 15
6963 0
8959 30
8789 0
8896 0
6963 0
8959 0
select KNO from Consumer where KNO in ('8789','8896','6963') and amount > 0
above query result is
KNO
8789
8896
I want query so that put particular KNO and get that KNO whose amount is 0
Output :
KNO
6963
June 27, 2014 at 10:30 am
atultiwari.eng06 (6/27/2014)
Table : ConsumerKNO Amount
8789 10
8896 15
6963 0
8959 30
8789 0
8896 0
6963 0
8959 0
select KNO from Consumer where KNO in ('8789','8896','6963') and amount > 0
above query result is
KNO
8789
8896
I want query so that put particular KNO and get that KNO whose amount is 0
Output :
KNO
6963
WHERE KNO in ('8789','8896','6963')
AND KNO = 0
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 27, 2014 at 10:35 am
WHERE KNO in ('8789','8896','6963')
AND KNO = 0
this will return empty records....
i want output
KNO
6963
June 27, 2014 at 11:40 am
SELECT KNO
FROM dbo.Consumer
WHERE KNO IN ('8789','8896','6963')
GROUP BY KNO
HAVING SUM(Amount) = 0
;
--Jeff Moden
Change is inevitable... Change for the better is not.
June 27, 2014 at 11:59 am
atultiwari.eng06 (6/27/2014)
WHERE KNO in ('8789','8896','6963')AND KNO = 0
this will return empty records....
i want output
KNO
6963
hehe meant to put Amount = 0. Hopefully the query Jeff posted is close to what you are looking for.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply