Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date query in Pervasive SQL database

Posted on 2014-09-05
2
Medium Priority
?
2,804 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 2000 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
What we learned in Webroot's webinar on multi-vector protection.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

664 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