Solved

MSSQL Import Source Query GETDATE Function

Posted on 2013-01-25
2
503 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
2 Comments
 
LVL 6

Accepted Solution

by:
liija earned 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

22 Experts available now in Live!

Get 1:1 Help Now