?
Solved

MSSQL Import Source Query GETDATE Function

Posted on 2013-01-25
2
Medium Priority
?
550 Views
Last Modified: 2013-01-25
Is there a way to utilize the GETDATE function in a source query for SQL Import/Export Wizard?

For example, I want to import data from a Pervasive table but limit the data to the last five years.  The SOURCE table has the field TransDateYYYYMMDD that I would like to use for this filter.  This query works fine:

SELECT * FROM <SOURCE> WHERE TRANSDATEYYYYMMDD>=20010101

but I would rather write something that uses a rolling date, like this

SELECT * FROM <SOURCE> WHERE TRANSDATEYYYYMMDD>=(year(getdate())-5)*10000+101

or something similar so that I would only import data for the last five years or so.

When I try to use the GETDATE function in the source query, MSSQL doesn't like it and says it's an "invalid user-defined or scalar function."
0
Comment
Question by:trbbhm
[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 6

Accepted Solution

by:
liija earned 2000 total points
ID: 38820416
If you are importing from pervasive-database, isn't that query going to Pervasive db then?
I mean your error is not SQL Server error, it's Pervasive error.

I'm not familiar with Pervasive SQL but you should use Pervasive's own function, similar to SQL Server's getdate().
0
 

Author Closing Comment

by:trbbhm
ID: 38820431
I certainly was not thinking along those lines.  Thank you for clearing my head!!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

718 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