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">
                <ItemTemplate>
                      <dx:ASPxLabel ID="lbldate" runat="server" Font-Size="Small" ForeColor="Red" Text='<%# BundleDate1Format(Eval("BundleDate1"))%>'>
                </dx:ASPxLabel></ItemTemplate></asp:FormView>
            </d

Open in new window

s
Southern_GentlemanAsked:
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.

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
0
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)
0
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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.
0
Scott PletcherSenior DBACommented:
What is the data type of column "BundleDate1"?  If it's varchar, you can just do something like below:

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

ISNULL(CAST(TRY_CONVERT(date, bundledDate ,101) AS VARCHAR) ,'')
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
Vikas GargBusiness Intelligence DeveloperCommented:
Hello,

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)

OR

SELECT *,
ISNULL(CONVERT(VARCHAR(50),DT),'Your Text Here') DT
FROM DimCustomer

Open in new window

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.