DYNAMIC SQL Select on char or varchar column
Posted in 1998
Topics: SQL Development & Query Writing, Data Types & Schema Design
Everytime a dynamic sql select returns a char or varchar field that is the
full length of the column, the last character will be missing; yet in the
database itself I know that the column includes the last character.
For Example:
create table abc (a char(3))
insert into table abc (a) values('one')
select * from abc where a = 'one'
(1 row returned)
select * from abc where a = 'on'
(0 rows returned)
BUT if I do the following dynamic sql query
sqlCommand = "select a from abc"
EXEC SQL prepare sqlcursor from :sqlCommand;
EXEC SQL declare selectCursor cursor for sqlcursor;
EXEC SQL describe sqlcursor into sqldaPtr;
EXEC SQL open selectCursor;
EXEC SQL fetch selectCursor using descriptor sqldaPtr;
My sqldata will only have 'on' rather than 'one'. It is the same for
varchar. All my other fields are totally fine.
Any suggestions would be greatly appreciated!
Alex