Solved

Date query in Pervasive SQL database

Posted on 2014-09-05
2
2,610 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
[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 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 49

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

623 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