Question

I am facing a problem for an hour or so with a LongText column in SQL. I am currently working on a web project where at some point we have a search form which allows user to search through numerous fields. Due to the customer's users being forced to use IE 9, we had to create a javascript... script, that parse the whole form and only takes what's needed in order not to exceed the 2k characters limit IE has.

So far so good, the script was working fine until we added a textarea field which represents a LongText column in our DB. The problem seems to come from the fact SQL won't take a simple String in an SQL statement as a LongText.

Here is what the query looks like:

SELECT * FROM SONORA.CF_CPR_CASE WHERE CASEFOLDERID != 2 
and CMF_VLM_APPLICATION like '%CPR%' and CPR_DESCRIPTION='rererere'
and CMF_TYPE_CASE_FK like '%LC_130125_074927_000001_60%' 

But I get this error:

EJBException:; nested exception is: javax.ejb.EJBException: The data types ntext
and varchar are incompatible in the equal to operator.S_EXCP(204); nested
exception is: javax.ejb.EJBException: The data types ntext and varchar
are incompatible in the equal to operator.S_EXCP(204)

Found in FmsQuery: SELECT * FROM {{DBTABLEPREFIX}}CF_CPR_CASE WHERE
CASEFOLDERID != 2 and CMF_VLM_APPLICATION like '%CPR%' and 
CPR_DESCRIPTION='ztztztztz' and CMF_TYPE_CASE_FK like 
'%LC_130125_074927_000001_60%'

We are using CASE360 which is not so known but still doesn't matter much, we are building the "where clause" of the SQL statement through javascript and then send it to the CASE360 processor which will take this all and execute the query. This part works fine, it's just the LongText column which is giving me a hard time.

If you guys have any idea what this SQL Query should look like to be successfully interpreted then I'd be infinitely happy!

Thank you for your help in advance.

Was it helpful?

Solution

You can try using a CAST on the column which is ntext. It's not clear to me which column that would be from the error above. As an example, let's assume it's the CPR_DESCRIPTION column:

SELECT *
FROM SONORA.CF_CPR_CASE
WHERE CASEFOLDERID != 2 
  and CMF_VLM_APPLICATION like '%CPR%'
  and CAST(CPR_DESCRIPTION as varchar(2000)) ='rererere'
  and CMF_TYPE_CASE_FK like '%LC_130125_074927_000001_60%'
;

Keep in mind that you need to pick an appropriately large varchar size for the cast, and that even with the maximum size there is a potential for data loss.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top