T-SQL: "01/01/1900" as Blank Date

Hello:

Below is my T-SQL code.  One of the lines in the code is the following:

CASE WHEN ME97708.ME_Job_Close_Date = '1900-01-01 00:00:00.000' then '' ELSE ME97708.ME_Job_Close_Date END AS [Close Date]

Instead of producing a blank field as I want for any dates that are 1900-01-01 00:00:00.000, I'm getting 1900-01-01 00:00:00.000.  How do I update that piece of the code to say just what I mentioned: produce a blank field for dates that are 1900-01-01 00:00:00.000?

Thanks!

TBSupport


select ME97705.ME_Job_ID as [Project #], ME97705.ME_User_Defined as [Editor], ME97705.DOCDATE as [Document Date], ME97708.ME_Work_Scope as [Product], ME97702.DSCRIPTN as [Company],
CASE WHEN GL00105.ACTNUMBR_1 = '4001' THEN ME97708.ME_Actual_Operating_Reve ELSE 0 END as [Sales],
GL00105.ACTNUMBR_1 as [Account], CASE WHEN GL00105.ACTNUMBR_1 <> '4001' THEN ME97705.TRXAMNT ELSE 0 END AS [Trans Amt],
--COALESCE(ME97708.ME_Job_Close_Date, '') AS [Close Date],
CASE WHEN ME97708.ME_Job_Close_Date = '1900-01-01 00:00:00.000' then '' ELSE ME97708.ME_Job_Close_Date END AS [Close Date]
from ME97705
INNER JOIN ME97708 on ME97705.ME_Job_ID = ME97708.ME_Job_ID
INNER JOIN GL00105 ON ME97705.ACTINDX = GL00105.ACTINDX
INNER JOIN ME97702 ON ME97708.CUSTNMBR = ME97702.MEuserdefined3
--where ME97708.CUSTNMBR = 'BCFB'
UNION ALL
select ME97704.ME_Job_ID as [Project #], ME97704.ME_User_Defined as [Editor], ME97704.DOCDATE as [Document Date], ME97707.ME_Work_Scope as [Product], ME97702.DSCRIPTN as [Company],
CASE WHEN GL00105.ACTNUMBR_1 = '4001' THEN ME97707.ME_Actual_Operating_Reve ELSE 0 END as [Sales],
GL00105.ACTNUMBR_1 as [Account], CASE WHEN GL00105.ACTNUMBR_1 <> '4001' THEN ME97704.TRXAMNT ELSE 0 END AS [Trans Amt],
--CASE WHEN ME97707.ME_Job_Close_Date = '01/01/1900' THEN COALESCE(ME97707.ME_Job_Close_Date, '') ELSE ME97707.ME_Job_Close_Date END as [Job Close Date]
--COALESCE(ME97707.ME_Job_Close_Date, '') As [Close Date],
CASE WHEN ME97707.ME_Job_Close_Date = '1900-01-01 00:00:00.000' then '' ELSE ME97707.ME_Job_Close_Date END AS [Close Date]
from ME97704
INNER JOIN ME97707 on ME97704.ME_Job_ID = ME97707.ME_Job_ID
INNER JOIN GL00105 ON ME97704.ACTINDX = GL00105.ACTINDX
INNER JOIN ME97702 ON ME97707.CUSTNMBR = ME97702.MEuserdefined3
--where ME97707.CUSTNMBR = 'BCFB'
LVL 1
TBSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Blanks aren't possible in a datetime data type, so how about NULL?

CASE WHEN ME_Job_Close_Date <> '1900-01-01 00:00:00.000' then Job_Close_Date ELSE NULL END AS [Close Date]

If you really want a blank, then the column needs to be CAST as a varchar.  
Not a big deal if this is for reports or an ETL job, but can cause problems if used by code that relies on the column being a date.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TBSupportAuthor Commented:
Hi Jim:

Thanks, for the quick response!

Did you mean for '1900-01-01 00:00:00.000' to be NULL?  I think that that would make the most sense (i.e. if the date is '1900-01-01 00:00:00.000', then make it NULL).

Maybe, I misinterpreted.  But, I just thought that I would ask.

Thanks!

TBSupport
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
<modified previous comment, hit Refresh>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.