Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

T-SQL, SQL Server Help

Posted on 2010-09-11
3
Medium Priority
?
321 Views
Last Modified: 2012-05-10
Hi all,

Bit of SQL help here, i'm really stuck been working on this for a couple hours. No idea why i'm getting an error whenever I run this SQL query, using a text driver through an ODBC connection to query a csv file...

Can anyone see anything wrong with my sql?

select  payee.*,
payee.AHIRDA+'/'+payee.AHIRMO+'/'+payee.AHIRYR AS Date_Of_Hire,
CASE ATRMDA
      WHEN 0 THEN '31/12/2999'
      ELSE payee.ATRMDA+'/'+payee.ATRMMO+'/'+ payee.ATRMYR
END AS Termination_Date
from
ptaagr0999.csv payee

Any help much appreciated.

I keep getting hte following error:

Syntax error(Missing operator) in query expression
'CASE ATRMDA
      WHEN 0 THEN '31/12/2999'
      ELSE payee.ATRMDA+'/'+payee.ATRMMO+'/'+ payee.ATRMYR
END'

Thanks a lot..
0
Comment
Question by:lp84
[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
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33652487
>using a text driver through an ODBC connection to query a csv file...you cannot do that, the text driver does not support all the MS SQL syntax.you have to load the text file with a plain SELECT * into a local table, and then query from there.this technique is called "staging" ...
0
 
LVL 12

Expert Comment

by:HugoHiasl
ID: 33652489
Which data type does ATRMDA have?

If it is date and you want to check for NULL you need to use

CASE ATRMDA
      WHEN NULL THEN '31/12/2999'
      ELSE payee.ATRMDA+'/'+payee.ATRMMO+'/'+ payee.ATRMYR
END AS Termination_Date

0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 33652904
If you are doing this from Access, then the CASE statement will not work.  As Angel mentioned, load the CSV file into an Access table.  Then, instead of using the Case statement, use the IIF( ) function

IIF(ATRMDA = 0, '31/12/2999', payee.ATRMDA+'/'+payee.ATRMMO+'/'+ payee.ATRMYR)
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

604 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