Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 00/00/0000 Data type Date ?Make Null?

Author  Topic 

rwaldron
Posting Yak Master

131 Posts

Posted - 2008-07-02 : 10:43:37
Hi all,
I have an SQL Server linked to a Btrieve server.

I want to query based on todays date.

However in Btrieve there is a column called say inshopdate....

Some entries in this column have the date as 00/00/0000
ie: there is no date yet.I cannot change the data in this table but I am assuming that this
column should be Null. The data type in Btrive for this table is of type DATE.

My problem is that When I query form sql to betrieve I want say a weeks worth of data
so in btrieve this is WHERE inshopdate >= curdat() -7.

My problem is that when sql hits a date of type 00/00/0000 the query falls over(and rightly so)
saying data in the column inshopdate is not of type datetime.

My question is how do I work around these dates so that my query finishes..

Would I need to do a make null where inshopdate = 00/00/0000
or where inshopdate is not date ?

Any ideas please,

Ray..

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-07-02 : 10:53:36
Update 00/00/0000 to 01/01/9999, go for the further process
Go to Top of Page

rwaldron
Posting Yak Master

131 Posts

Posted - 2008-07-02 : 11:00:49
Hi and thx for the reply.
I don't know what you mean by Update 00/00/0000 to 01/01/9999, go for the further process

Could you please explain
Thx
Ray..
Go to Top of Page

mcrowley
Aged Yak Warrior

771 Posts

Posted - 2008-07-02 : 11:22:26
Can you have a view created on the BTrieve side that aliases the 00/00/000 values to a valid SQL Server datetime value?
Go to Top of Page

rwaldron
Posting Yak Master

131 Posts

Posted - 2008-07-02 : 11:30:34
Hiya,
I cany really touch the Btrieve side at all its not my data.
The SQL side is mine..
Any other help please
Go to Top of Page

mcrowley
Aged Yak Warrior

771 Posts

Posted - 2008-07-02 : 11:35:03
OK. when you select the data from the linked server, do the 00/00/0000 values come through (i.e. when you do not attempt any comparisons against them)? If so, can you cast or convert these values to varchar(10)?
Go to Top of Page

rwaldron
Posting Yak Master

131 Posts

Posted - 2008-07-02 : 12:35:28
Hiya and thx for your help.
In Btrieve I know order 361019 has inworkshopdate as 00/00/0000.
If I run below query with no comparisons but where refnumber = 361019
SQL gives me back the error."Conversion failed because the data valus overflowed the datatype used by the provider"
select *
FROM (SELECT RefNumber, InWorkShopDate, InWorkShopTime
FROM OPENQUERY(sbase_live_link,
'SELECT refnumber,InWorkShopDate,InWorkShopTime FROM JOBSE where refnumber = 361019 order by InWorkShopTime desc ')
AS derivedtbl_1) AS JOBSE LEFT OUTER JOIN
(SELECT RefNumber, Invoice_Text
FROM OPENQUERY(sbase_live_link, 'SELECT RefNumber,Invoice_Text FROM JOBNOTES ') AS derivedtbl_1_1) AS JOBNOTES ON
JOBSE.RefNumber = JOBNOTES.RefNumber


My Working Solution is below...The problem is that it takes over 50 Minutes to run !!!!!!!
This is where I check for 00/00/0000 and if found make null.
My sql query finishes.The dates in SQL don't show up as Null but 0000-00-00
Work around so far is below but it takes too long

FROM (SELECT RefNumber, InWorkShopDate, InWorkShopTime
FROM OPENQUERY(sbase_live_link,
'SELECT refnumber,Case When InWorkShopDate like ''00/00/0000'' then null else Convert(jobse.InWorkShopDate, SQL_VARCHAR)END InWorkShopDate,Convert(jobse.InWorkShopTime, SQL_VARCHAR)AS InWorkShopTime FROM JOBSE where inworkshopdate >= curdate()- 4 order by InWorkShopDate desc ')
AS derivedtbl_1) AS JOBSE LEFT OUTER JOIN
(SELECT RefNumber, Invoice_Text
FROM OPENQUERY(sbase_live_link, 'SELECT RefNumber,Invoice_Text FROM JOBNOTES ') AS derivedtbl_1_1) AS JOBNOTES ON
JOBSE.RefNumber = JOBNOTES.RefNumber

Go to Top of Page
   

- Advertisement -