Solved

Date query in Pervasive SQL database

Posted on 2014-09-05
2
1,965 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Here's a requirements document template for an integration project (also known as Extract-Transform-Load or ETL) based on my development experience as an SQL Server Information Services (SSIS) developer over the years.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now