Solved

MSSQL Import Source Query GETDATE Function

Posted on 2013-01-25
2
510 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Required 3 96
Query Help - MSSQL - Averages 5 27
Sql Query 6 66
Rename a column in the output 3 14
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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

773 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