Skip to Content
author's profile photo Former Member
Former Member

Trying to replace a 'default date' with a 'blank cell' (data presentation issue)?

Hi Everyone,

I am trying to add the total cost of purchases to a reports that shows 'row level' items and costs. To do this I have used the UNION ALL command, as shown below.

SELECT
T1.DocDate
, T0.Dscription AS 'Item Description'
, T0.Price

FROM AU.dbo.POR1 T0
INNER JOIN AU.dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry

WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'

UNION ALL

SELECT
--CASE WHEN CAST(SUM(0) AS varchar) = '1900-01-01 00:00:00.000' THEN 'A' ELSE 'B' END
''
, 'Total Cost'
, SUM(T0.Price)

FROM AU.dbo.POR1 T0
INNER JOIN AU.dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry

WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'

I am getting the results that I expect however instead of seeing '1900-01-01 00:00:00.000' in the bottom left hand corner of my result set I would simply like to see a blank cell (with no contents).

Here is what I am currently seeing -

How can I 'remove the contents' and substitute a 'blank'? I tried using a case statement and the SUM operator without success. I chose SUM, because to choose a non-aggregate function would require me to use the GROUP BY clause, and doing so would then affect my result set adversely.

Any suggests here will be greatly appreciated.

Kind Regards,

David

Capture.JPG (89.9 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Jul 21, 2014 at 05:15 AM

    HI David...

    Can u pass the Getdate on the total query.. which makes a meaning report.

    Provide your feedback

    Rgds

    Kennedy

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 21, 2014 at 06:00 AM

    Hi ,

    Try this below query and let know your feedback,

    SELECT

    CONVERT(VARCHAR(11),T1.DocDate,110 ) [Docdate]

    , T0.Dscription AS 'Item Description'

    , T0.Price

    FROM dbo.POR1 T0

    INNER JOIN dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry

    WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'

    UNION ALL

    SELECT

    --CASE WHEN CAST(SUM(0) AS varchar) = '1900-01-01 00:00:00.000' THEN 'A' ELSE 'B' END

    CONVERT(VARCHAR(19),'---' ) [Docdate]

    , 'Total Cost'

    , SUM(T0.Price)

    FROM dbo.POR1 T0

    INNER JOIN dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry

    WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 21, 2014 at 06:01 AM

    Hi!

    Try This.

    1. SELECT
    2. cast(T1.DocDate as varchar) 'Date'
    3. , T0.Dscription AS 'Item Description'
    4. , T0.Price
    5. FROM AU.dbo.POR1 T0
    6. INNER JOIN AU.dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry
    7. WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'
    8. UNION ALL
    9. SELECT
    10. --CASE WHEN CAST(SUM(0) AS varchar) = '1900-01-01 00:00:00.000' THEN 'A' ELSE 'B' END
    11. '' 'Date'
    12. , 'Total Cost'
    13. , SUM(T0.Price)
    14. FROM AU.dbo.POR1 T0
    15. INNER JOIN AU.dbo.OPOR T1 ON T1.DocEntry = T0.DocEntry
    16. WHERE T1.DocType = 'S' AND T1.CardCode = 'V010050'


    Regards,

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.