[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Null dates and 1900-01-01 and sql server 2008

Posted on 2010-08-28
5
Medium Priority
?
1,393 Views
Last Modified: 2012-05-10

Hello,

We have upgraded Sql Server 2005 to Sql Server 2008.
Date values for a particular variable now display 1900-01-01 when the date is null.  

The variable is declared in this way:
Let $Activity_Date       = &B.LAST_ACTIVITY_DATE

When I tests for nulls,
 let #value_null= ISNULL($Activity_Date)
    if #value_null= 1
         #DEBUG SHOW '************$Activity_Date here'  $Activity_Date
    end-if

In the trace file, I see that the value is null, yet in sql server when this value is inserted into a table it displays as 1900-01-01.  I want this to display this as a blank.

I know that a vaule that is 0 or '   ' will display as 1900-01-01 but I clearly can see that the value is null ,

What cast statment can I use in the insert to avoid this.

Thanks,
nigluc
0
Comment
Question by:Lucia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 33552295
Hi,

Are you using LINQ?

The corect T-SQL syntax is

if exists(
  select 1
  from <yourtablename>
  where
    <yourcolumn> is null
  )
  <true clause here>

I suspect that the ISNULL($Activity_Date) is responsible for yoru dilema.

Regards
  David
0
 

Author Comment

by:Lucia
ID: 33553046
Hi David,

In SQR to check for the presence of a value using an if statement, you can use ISNULL. The syntax explanation is this :

ISNULL
-------
Returns a value of one (1) if source_val is null; otherwise, returns a
value of zero (0).

Syntax:

dst_var = isnull(source_value)
source_value = date or text literal, column, variable, or expression

dst_var = decimal, float, or integer variable

Example:

let #null = isnull($date)

***************************************************************************************************************
What happens next in the program is that we do an insert sql statment:

begin-sql
INSERT INTO PS_NCSF4204
      (OPRID
      ,RUN_CNTL_ID
      ,EMPLID
      ,ACCOUNT_TYPE_SF
      ,TERM_DESCR
      ,ITEM_NBR
      ,DESCR
      ,AMOUNT
      ,ITEM_TYPE_CD
      ,LAST_ACTIVITY_DATE
      ,STRM)
VALUES
      ($_prcs_oprid
      ,$_prcs_run_cntl_id
      ,$Emplid
      ,$Account_Type_SF
      ,$_DescrShort
      ,$Item_Nbr
      ,$Descr
      ,#Total
      ,$Item_Type_CD
      ,  !SNULL ( CONVERT(varchar(10),$Activity_Date, 120), ' ' )
                      ,$Term)
end-sql
 

   ************************************************************************************************************
So, I tried the ,  !SNULL ( CONVERT(varchar(10),$Activity_Date, 120), '  ' )
to get a blank date instead of 1900-01-01  but that does not work. When I query NCSF4204, i still see the 1900-01-01 where the dates were supposedly null.

Thank you,
Lucy
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 33553244
ISNULL ( CONVERT(varchar(10),$Activity_Date, 120), ' ' )

Would definitely produce '1900-01-01' by your own words above as '' or ' ' or 0 will result in default datetime value with is '1900-01-01'.  If the value is NULL at some point in your code, something has to be converting this to an empty string or something.

Otherwise, how are you checking if the data is NULL in the database?  Are you looking in SQL Management Studio at the raw data ? Just make sure the query to get data isn't using coalesce or isnull to convert to to date 0 if the value is NULL.

Is the column set to allow NULL dates, maybe it has a default of 0 specified.
0
 

Author Comment

by:Lucia
ID: 33553853
 !SNULL ( CONVERT(varchar(10),$Activity_Date, 120), ' ' )


Hi,

Sorry about that it should be a null.  Regardless, it did not work.  It still gave a null.  

I checked the table design. For that particular column , the allow null column is checked off in Sql Analyzer.

Also, as you have suggested, looked in the original table where the value is picked up and
and there there is no coalesce or null being used.

I also did a query on this original table liike this :
Select * from PS_ITEM_SF table where LAST_ACTIVITY_DATE  IS NULL.

No rows were  returned.

Yet when I feed the value into the statement like this

:Let $Activity_Date       = &B.LAST_ACTIVITY_DATE

and insert into the table I get this 1900-01-01 for values that don't exist.

A collegue suggested that I explicitly declare the  $Activity_Date   as  a date variable but that did not work either.

Right now I just suppress it in the Crystal.

Thank you,
Lucy





 
0
 
LVL 35

Accepted Solution

by:
David Todd earned 2000 total points
ID: 33553981
Hi Lucy,

I've found that things work better when I return the datetime to crystal as a datetime - including nulls - and let Crystal worry about the formatting.

If on the other hand you convert the datetime to a varchar in SQL, then that can affect sorting. The datetimes will in a properly built anything sort, whereas once they are string values all bets are off.

08-30-2010
08-31-2010
08-4-2010
08-5-2010

... for instance

HTH
  David
 
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question