 |
|
 |
|
Next: Web Datablade
|
| Author |
Message |
External

Since: Jun 10, 2008 Posts: 63
|
(Msg. 1) Posted: Wed Dec 10, 2008 4:25 am
Post subject: How to avoid displaying rows with all zeros Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
Hi!
The table is as follows:
[Item Description] varchar,
Vasche datetime,
Imballo datetime,
Schiumatura datetime,
Alienato datetime,
[Prod_ Order No_] varchar
I run the following query:
DECLARE @tmpStartDate datetime
DECLARE @tmpEndDate datetime
SET @tmpStartDate = '2008-12-09'
SET @tmpEndDate = '2008-12-09'
SELECT [Item Description], [Prod_ Order No_],
SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Vasche,
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1 ELSE 0 END) as Schiumatura,
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Imballo,
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Alienato
FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
GROUP BY [Item Description], [Prod_ Order No_]
I need to modify it so that it will not display rows in cases when there're
all zeros in the produced row.
I was thinking on doing like bellow, but it won't work:
DECLARE @tmpStartDate datetime
DECLARE @tmpEndDate datetime
SET @tmpStartDate = '2008-12-09'
SET @tmpEndDate = '2008-12-09'
SELECT [Item Description], [Prod_ Order No_],
SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Vasche,
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1 ELSE 0 END) as Schiumatura,
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Imballo,
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Alienato
FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
HAVING
SUM(SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) +
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1 ELSE 0 END) +
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) +
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END)) > 0
GROUP BY [Item Description], [Prod_ Order No_]
How can I obtain the desired result? >> Stay informed about: How to avoid displaying rows with all zeros |
|
| Back to top |
|
 |  |
External

Since: Jan 23, 2008 Posts: 63
|
(Msg. 2) Posted: Wed Dec 10, 2008 4:25 am
Post subject: Re: How to avoid displaying rows with all zeros [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
You can try something like
DECLARE @tmpStartDate datetime
DECLARE @tmpEndDate datetime
SET @tmpStartDate = '2008-12-09'
SET @tmpEndDate = '2008-12-09'
Select * from
(
SELECT [Item Description], [Prod_ Order No_],
SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1
ELSE 0 END) as Vasche,
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
THEN
1 ELSE 0 END) as Schiumatura,
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
THEN 1
ELSE 0 END) as Imballo,
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
THEN 1
ELSE 0 END) as Alienato
FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
GROUP BY [Item Description], [Prod_ Order No_]
)t
where
Vasche + Schiumatura + Imballo + Alienato <> 0 >> Stay informed about: How to avoid displaying rows with all zeros |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2003 Posts: 1744
|
(Msg. 3) Posted: Wed Dec 10, 2008 5:25 am
Post subject: Re: How to avoid displaying rows with all zeros [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Zaur
WITH cte
AS
(
SELECT [Item Description], [Prod_ Order No_],
SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Vasche,
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1 ELSE 0 END) as Schiumatura,
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Imballo,
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) as Alienato
FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
GROUP BY [Item Description], [Prod_ Order No_]
) SELECT * FROM Vasche >0..........................
"Zaur Bahramov" wrote in message
> Hi!
>
> The table is as follows:
>
> [Item Description] varchar,
> Vasche datetime,
> Imballo datetime,
> Schiumatura datetime,
> Alienato datetime,
> [Prod_ Order No_] varchar
>
> I run the following query:
>
> DECLARE @tmpStartDate datetime
> DECLARE @tmpEndDate datetime
> SET @tmpStartDate = '2008-12-09'
> SET @tmpEndDate = '2008-12-09'
>
> SELECT [Item Description], [Prod_ Order No_],
> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Vasche,
> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) as Schiumatura,
> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Imballo,
> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Alienato
> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
> GROUP BY [Item Description], [Prod_ Order No_]
>
> I need to modify it so that it will not display rows in cases when
> there're all zeros in the produced row.
>
> I was thinking on doing like bellow, but it won't work:
> DECLARE @tmpStartDate datetime
> DECLARE @tmpEndDate datetime
> SET @tmpStartDate = '2008-12-09'
> SET @tmpEndDate = '2008-12-09'
>
> SELECT [Item Description], [Prod_ Order No_],
> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Vasche,
> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) as Schiumatura,
> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Imballo,
> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Alienato
> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
> HAVING
> SUM(SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) +
> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) +
> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) +
> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END)) > 0
> GROUP BY [Item Description], [Prod_ Order No_]
>
> How can I obtain the desired result?
>
> >> Stay informed about: How to avoid displaying rows with all zeros |
|
| Back to top |
|
 |  |
External

Since: Jun 10, 2008 Posts: 63
|
(Msg. 4) Posted: Wed Dec 10, 2008 5:25 am
Post subject: Re: How to avoid displaying rows with all zeros [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I've added the
HAVING SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
THEN 1 ELSE 0 END) <> 0 OR
SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
1 ELSE 0 END) <> 0 OR
SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) <> 0 OR
SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
ELSE 0 END) <> 0
After GROUP BY
so it seems working fine for me. Is it OK, or better to use the query by
Uri?
"Uri Dimant" ha scritto nel messaggio
> Zaur
>
> WITH cte
> AS
> (
> SELECT [Item Description], [Prod_ Order No_],
> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Vasche,
> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) as Schiumatura,
> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Imballo,
> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) as Alienato
> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
> GROUP BY [Item Description], [Prod_ Order No_]
>
> ) SELECT * FROM Vasche >0..........................
>
> "Zaur Bahramov" wrote in message
>
>> Hi!
>>
>> The table is as follows:
>>
>> [Item Description] varchar,
>> Vasche datetime,
>> Imballo datetime,
>> Schiumatura datetime,
>> Alienato datetime,
>> [Prod_ Order No_] varchar
>>
>> I run the following query:
>>
>> DECLARE @tmpStartDate datetime
>> DECLARE @tmpEndDate datetime
>> SET @tmpStartDate = '2008-12-09'
>> SET @tmpEndDate = '2008-12-09'
>>
>> SELECT [Item Description], [Prod_ Order No_],
>> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Vasche,
>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>> THEN 1 ELSE 0 END) as Schiumatura,
>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Imballo,
>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Alienato
>> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
>> GROUP BY [Item Description], [Prod_ Order No_]
>>
>> I need to modify it so that it will not display rows in cases when
>> there're all zeros in the produced row.
>>
>> I was thinking on doing like bellow, but it won't work:
>> DECLARE @tmpStartDate datetime
>> DECLARE @tmpEndDate datetime
>> SET @tmpStartDate = '2008-12-09'
>> SET @tmpEndDate = '2008-12-09'
>>
>> SELECT [Item Description], [Prod_ Order No_],
>> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Vasche,
>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>> THEN 1 ELSE 0 END) as Schiumatura,
>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Imballo,
>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Alienato
>> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
>> HAVING
>> SUM(SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
>> 1 ELSE 0 END) +
>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>> THEN 1 ELSE 0 END) +
>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) +
>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END)) > 0
>> GROUP BY [Item Description], [Prod_ Order No_]
>>
>> How can I obtain the desired result?
>>
>>
>
> >> Stay informed about: How to avoid displaying rows with all zeros |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2003 Posts: 1744
|
(Msg. 5) Posted: Wed Dec 10, 2008 5:25 am
Post subject: Re: How to avoid displaying rows with all zeros [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Zaur
More readable......
"Zaur Bahramov" wrote in message
> I've added the
> HAVING SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
> THEN 1 ELSE 0 END) <> 0 OR
> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
> THEN 1 ELSE 0 END) <> 0 OR
> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
> ELSE 0 END) <> 0 OR
> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
> 1 ELSE 0 END) <> 0
>
> After GROUP BY
> so it seems working fine for me. Is it OK, or better to use the query by
> Uri?
>
>
>
> "Uri Dimant" ha scritto nel messaggio
>
>> Zaur
>>
>> WITH cte
>> AS
>> (
>> SELECT [Item Description], [Prod_ Order No_],
>> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Vasche,
>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>> THEN
>> 1 ELSE 0 END) as Schiumatura,
>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Imballo,
>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>> ELSE 0 END) as Alienato
>> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
>> GROUP BY [Item Description], [Prod_ Order No_]
>>
>> ) SELECT * FROM Vasche >0..........................
>>
>> "Zaur Bahramov" wrote in message
>>
>>> Hi!
>>>
>>> The table is as follows:
>>>
>>> [Item Description] varchar,
>>> Vasche datetime,
>>> Imballo datetime,
>>> Schiumatura datetime,
>>> Alienato datetime,
>>> [Prod_ Order No_] varchar
>>>
>>> I run the following query:
>>>
>>> DECLARE @tmpStartDate datetime
>>> DECLARE @tmpEndDate datetime
>>> SET @tmpStartDate = '2008-12-09'
>>> SET @tmpEndDate = '2008-12-09'
>>>
>>> SELECT [Item Description], [Prod_ Order No_],
>>> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>>> ELSE 0 END) as Vasche,
>>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>>> THEN 1 ELSE 0 END) as Schiumatura,
>>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>>> ELSE 0 END) as Imballo,
>>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
>>> 1 ELSE 0 END) as Alienato
>>> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
>>> GROUP BY [Item Description], [Prod_ Order No_]
>>>
>>> I need to modify it so that it will not display rows in cases when
>>> there're all zeros in the produced row.
>>>
>>> I was thinking on doing like bellow, but it won't work:
>>> DECLARE @tmpStartDate datetime
>>> DECLARE @tmpEndDate datetime
>>> SET @tmpStartDate = '2008-12-09'
>>> SET @tmpEndDate = '2008-12-09'
>>>
>>> SELECT [Item Description], [Prod_ Order No_],
>>> SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>>> ELSE 0 END) as Vasche,
>>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>>> THEN 1 ELSE 0 END) as Schiumatura,
>>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>>> ELSE 0 END) as Imballo,
>>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
>>> 1 ELSE 0 END) as Alienato
>>> FROM [dbo].[Mondial Group s_r_l_$Production Cycle]
>>> HAVING
>>> SUM(SUM(CASE WHEN Vasche BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>>> THEN 1 ELSE 0 END) +
>>> SUM(CASE WHEN Schiumatura BETWEEN (@tmpStartDate) AND (@tmpEndDate+1)
>>> THEN 1 ELSE 0 END) +
>>> SUM(CASE WHEN Imballo BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN 1
>>> ELSE 0 END) +
>>> SUM(CASE WHEN Alienato BETWEEN (@tmpStartDate) AND (@tmpEndDate+1) THEN
>>> 1 ELSE 0 END)) > 0
>>> GROUP BY [Item Description], [Prod_ Order No_]
>>>
>>> How can I obtain the desired result?
>>>
>>>
>>
>>
>
> >> Stay informed about: How to avoid displaying rows with all zeros |
|
| Back to top |
|
 |  |
| Related Topics: | Format numbers to use leading zeros - Hello, I'm trying to concatenate the year and month of a date and need the leading zero to show in the month, so '3' becomes '03'. Is there a way to do this in T-SQL? Rick
Excluding rows that have no child rows in a hireachy type .. - Hi All, I have inherited a badly designed database. ANyway, I have a table that is losely based on a hirearchy type table l2,l3,l4, relate to the hirearchy. l2 is the parent, l3 is first node/child, l4 is secont node/ grand child. What I want is to..
Converting Multiple Rows Into Single CSV Rows - Hi, Hoping someone could help me convert this data... ID Size 60203 M 60203 L 60203 XXL 30020 10 30020 8 ....into this... ID Size 60203 M,L,XXL 30020 10,8 Any help would be greatly appreciated. Thx, EightBall
How to avoid Deadlocks - I am facing the following problem with deadlocks: I have written a set of stored procedures which invoices orders in a database. First some general explanation: There exists a table for orders and a table for order positions referencing the order..
How to avoid use cursor in this situation - I have a function to convert string to a table. If you pass string like '1,2,3,4,5' to it, it returns 1 2 3 4 5 Here is the question: I need to parse strings stored in another table. I use cursor to do this job in my sample code below. How can I avoid... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|