Solved

Date query in Pervasive SQL database

Posted on 2014-09-05
2
2,317 Views
Last Modified: 2016-02-11
I have the following query below in Microsoft SSIS when I sync data from Pervasive SQL to MS SQL

Now I want to run the same query in Pervasive SQL Control Center which does not work. I want to run the query in Pervasive to return results where I can specify either the days, months, or years

Then I also want to format the date as DD/MM/YYYY or dd-mm-yyyy. The date format in Pervasive SQL is a string as 20131129 which is Nov 29 2013

SELECT NUMBER
      ,RECNO
      ,WHSE
      ,CODE
      ,SHD_DESCRIPTION
      ,PROD_CODE      
  FROM SALES_HISTORY_DETAIL
WHERE BVRVADDDATE > (SELECT GETCCCDATE(1));
0
Comment
Question by:Gerhardpet
2 Comments
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 40306234
Developers have the freedom to use whatever date format they like in applications, and the developer whose database you are accessing took such liberties, opting to use a string field instead of a date field.

If the developer included a key on the date field, then you REALLY want to use that key in a query like this, otherwise, you'll end up with a full table-scan for every query.  To do this, you MUST convert the date you want to search on to a string, and THEN use this string for the WHERE clause.

Luckily, as a string, this field collates properly, so you can use a query like this:
    SELECT * FROM Sales_History_Detail WHERE BvrvAddDate > '20140101'
to get all records from 2014.  

You can also use the LIKE parameter to dig into the string, too.  For example, to get all records from September, use:
    WHERE BvrvAddDate LIKE '____09__'
That won't use a key and will need a table-scan, but that would be expected.

To reformat the date, you'll just have to manipulate the string with the string scalar functions:
    SELECT Right(BvrvAddDate,2) + '-' + Left(Right(BvrvAddDate,4),2) + '-' + Left(BvrvAddDate,4) FROM ...
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40309219
>>"The date format in Pervasive SQL is a string as 20131129 "

Do you know what the actual data type for that column is?
What is GETCCCDATE(1)? (it's not a system function) What data type does it return?

>>"... which does not work"
what is the error message? else; what is the symptom of 'does not work'?
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SCOM to SQL port 14xx failed? 1 30
sql query 5 44
Checking for column changes SQL 2014 4 20
error in oracle form 11 21
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

756 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