Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Table problem

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-28 : 07:40:26
Mr.x writes "

----First Table:----With Zeroes


can any body help me.........
iss_quantity received_qty moved_qty alloc_qty
------------------------------ --------------------
14 0 0 0
0 0 0 0
0 0 13.7 0
0 0 0 13
14 0 0 0
14 0 0 0
0 40.9 0 0
14 0 0 0
0 0 13.8 0
0 27.6 0 0
0 0 13.8 0
0 0 13.7 0
0 0 13.8 0
0 41.4 0 0
0 0 13.9 0
0 0 0 13
14 0 0 0



----Resultant Table:----Without Zeroes

iss_quantity received_qty moved_qty alloc_qty
------------------------------ --------------------
14 40.9 13.7 13
14 27.6 13.8 13
14 41.4 13.8
14 13.7
14 13.8
13.9

"

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-06-28 : 07:48:40
So how do you split these into their groups?!?!?!
Go to Top of Page

Mr.Xyz
Starting Member

5 Posts

Posted - 2004-06-29 : 02:36:25
quote:
Originally posted by RickD

So how do you split these into their groups?!?!?!


There is no grouping.,
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-29 : 22:51:21
SELECT
iss_quantity,
CASE WHEN received_qty = 0 THEN '' ELSE received_qty END received_qty,
CASE WHEN moved_qty = 0 THEN '' ELSE moved_qty END moved_qty,
CASE WHEN alloc_qty = 0 THEN '' ELSE alloc_qty END alloc_qty
FROM quantities
WHERE
(received_qty <> 0
OR moved_qty <> 0
OR alloc_qty <> 0)

This should be really efficient also. (cough, cough)


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Mr.Xyz
Starting Member

5 Posts

Posted - 2004-06-30 : 04:29:02
quote:
Originally posted by derrickleggett

SELECT
iss_quantity,
CASE WHEN received_qty = 0 THEN '' ELSE received_qty END received_qty,
CASE WHEN moved_qty = 0 THEN '' ELSE moved_qty END moved_qty,
CASE WHEN alloc_qty = 0 THEN '' ELSE alloc_qty END alloc_qty
FROM quantities
WHERE
(received_qty <> 0
OR moved_qty <> 0
OR alloc_qty <> 0)

This should be really efficient also. (cough, cough)


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.


can be done but can't convert varchar to numeric
since all these qtys are numeric
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-30 : 08:37:19
Of course it can be done. That's rarely ever the answer.


DECLARE @quantities TABLE(
iss_quantity INT,
received_qty INT,
moved_qty INT,
alloc_qty INT)

INSERT @quantities(iss_quantity, received_qty, moved_qty, alloc_qty)
SELECT 14,0,0,0
UNION ALL
SELECT 0,0,0,0
UNION ALL
SELECT 0,0,13.7,0
UNION ALL
SELECT 14,27.6,0,5

SELECT
CASE WHEN iss_quantity = 0 THEN '' ELSE CAST(iss_quantity AS VARCHAR(55)) END iss_quantity,
CASE WHEN received_qty = 0 THEN '' ELSE CAST(received_qty AS VARCHAR(55)) END received_qty,
CASE WHEN moved_qty = 0 THEN '' ELSE CAST(moved_qty AS VARCHAR(55)) END moved_qty,
CASE WHEN alloc_qty = 0 THEN '' ELSE CAST(alloc_qty AS VARCHAR(55)) END alloc_qty
FROM @quantities
WHERE
(received_qty <> 0
OR moved_qty <> 0
OR alloc_qty <> 0)


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -