If Date is Null then text

I'm simply trying to add a text in my label if the date value of my query is NULL. Just like most scenarios when it is null the value of my label returns 01/01/1900

SELECT BundleID1, CAST(ISNULL(TRY_CONVERT(date,BundleDate1,101),'') As Date) AS BundleDate1 FROM PreBuyBundle WHERE (ID = 23)

Open in new window

My ASPX markup
<asp:FormView ID="formview54" runat="server" DataSourceID="sqlfinddate">
                      <dx:ASPxLabel ID="lbldate" runat="server" Font-Size="Small" ForeColor="Red" Text='<%# BundleDate1Format(Eval("BundleDate1"))%>'>

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Aneesh RetnakaranDatabase AdministratorCommented:
CAST(ISNULL(CAST(TRY_CONVERT(date, bundledDate ,101) AS VARCHAR) ,'') As Date)

You are converting bundledDate  to Datetype, so, the ISNULL will convert '' to a date which is by default 1900-01-01
Brian CroweDatabase AdministratorCommented:
You will need to handle this in your presentation layer.  I would suggest just returning a NULL and adjusting your ASPX to replace that with an appropriate label.  Alternatively you would have to convert all of the dates to strings then you could insert the string value in the query output.

SELECT BundleID1, ISNULL(TRY_CONVERT(date,BundleDate1,101),'Label Here') AS BundleDate1String
FROM PreBuyBundle WHERE (ID = 23)
Southern_GentlemanAuthor Commented:
im still getting the 1900-01-01 as a display in my label Aneesh.  

SELECT BundleID1, CAST(ISNULL(CAST(TRY_CONVERT(date,BundleDate1,101) AS VARCHAR),'') As Date) AS BundleDate1 FROM PreBuyBundle WHERE (ID = 23)

Brian can you give me an example.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Brian CroweDatabase AdministratorCommented:
What format do you want to display the date in within your application?

From your example remove the outer CAST to DATE and put your desired label in the second parameter of the ISNULL function.
Scott PletcherSenior DBACommented:
What is the data type of column "BundleDate1"?  If it's varchar, you can just do something like below:

    CASE WHEN ISDATE(BundleDate1) = 1 THEN BundleDate1 ELSE '' END AS BundleDate1
FROM PreBuyBundle WHERE (ID = 23)
Aneesh RetnakaranDatabase AdministratorCommented:
My bad , you don't need the outer  CAST

ISNULL(CAST(TRY_CONVERT(date, bundledDate ,101) AS VARCHAR) ,'')

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
Vikas GargAssociate Principal EngineerCommented:

You can try this simple code

SELECT BundleID1, 
CASE WHEN BundleDate1 IS NULL THEN 'Your Text Here' ELSE CONVERT(VARCHAR(50),BundleDate1)  END AS BundleDate1 
FROM DimCalendar WHERE (ID = 23)


FROM DimCustomer

Open in new window

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.