Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Query from SQL to AS400 0206 and 0420 errors

$
0
0

I have been working on a query from out of SQL via a linked server to an AS400

I seem to have 2 issues that I cannot get past.

Below is the query:

select * from openquery(IBM, 'SELECT T.ATTY, M.MMNBAT, T.CLNT, M.MTTR, sum(TMBH + TNBH) AS HOURS  
FROM LMSFILLIB.TRNW t LEFT OUTER JOIN LMSFILLIB.MATTER m on T.CLNT=M.CLNT and T.MTTR=M.MTTR
WHERE (T.FSCY*100 + T.PRD) between 201301 and 201308 and T.CLNT <> 0000000000 and T.ATTY <> M.MMNBAT
GROUP BY T.ATTY,M.MMNBAT,T.CLNT,M.MTTR HAVING HOURS >=20 FOR READ ONLY') 

1. The first issue is if I define 'Hours' using 'AS', I get an ERROR "SQL0206: Column Hours not in specified tables).  The two columns I am summing are decimal fields

2. If I remove AS HOURS from my select statement and swap the HOURS with sum(TMBH + TNBH) >= 20 in the Having statement, I receive "SQL0420: Character in CAST argument not valid"

I would ultimately like to sum the two columns as hours, but even trying to sum the two columns I get errors.  Anything that I am doing blatantly wrong?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>