Solved

T-SQL, SQL Server Help

Posted on 2010-09-11
3
273 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
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>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
Comment Utility
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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

10 Experts available now in Live!

Get 1:1 Help Now