File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to Convert type in sql or jasper i report Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to Convert type in sql or jasper i report" Watch "How to Convert type in sql or jasper i report" New topic
Author

How to Convert type in sql or jasper i report

Kaustubh Sharma
Greenhorn

Joined: Mar 02, 2010
Posts: 28
hi .......

in my sql query i want to change bit type 0 or 1 in values 'Yes' or 'No' but while runnig query below I am getting

Error: Conversion failed when converting the varchar value 'No' to data type bit.

Query:select case casedetails.[re-openindicator] when 1 then 'Yes' when 0 then 'No' else casedetails.[re-openindicator] end from casedetails

Well I am also passing this query to Jasper I report but there also it is converting it into boolean values false or true but I want it as Yes or No...


looking for a sharp Brain to solve my problem ..... please help me out to convert it any side(jasper i report or in sql query)

Thanks in Advance

Kaustubh
Kaustubh Sharma
Greenhorn

Joined: Mar 02, 2010
Posts: 28




This is the code in my jasper i report
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

kaustubh sharma wrote:select case casedetails.[re-openindicator] when 1 then 'Yes' when 0 then 'No' else casedetails.[re-openindicator] end from casedetails

If the bit is neither 0 not 1 (this will not happen but the SQL engine cannot see that) the returned column will still be of type bit. Instead of converting this into a varchar the "Yes" and "No" are attempted to be converted back into a bit.

The following two would solve this:
1) select case casedetails.[re-openindicator] when 0 then 'No' else 'Yes' end from casedetails -- anything that isn't 0 will be treated as "Yes"
2) select case casedetails.[re-openindicator] when 1 then 'Yes' when 0 then 'No' else cast(casedetails.[re-openindicator] as varchar) end from casedetails -- convert the bit into a varchar

Now I am aware that you are probably not in control of the generated SQL queries, but you must find a way to let Jasper use either SQL statement.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kaustubh Sharma
Greenhorn

Joined: Mar 02, 2010
Posts: 28
it is working Rob ..You Rock Man. You are My Hero. .......
Beer for all..

Thanks Buddy

Kaustubh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Convert type in sql or jasper i report