I'm using powerbuilder 10.2
I have a simple select statement that returns one result from a table with 3 million rows.
SELECT SOME_DATA
INTO :ls_data
FROM SOME_TABLE
WHERE PARAM1 = :ls_param
AND PARAM2 = :ls_param2;
When I run the query in application, it takes about 2 seconds but when I run it in SSMS, the result returns in less than 100 milliseconds. And I've made a pretty interesting discovery when I captured the query being ran from powerbuilder application with SQL profiler:
exec sp_executesql N'SELECT SOME_DATA FROM SOME_TABLE WHERE PARAM1 =@P1 AND PARAM2 =@P2 ',N'@P1 nvarchar(10),@P2 nvarchar(3)',N'112223',N'44252525'
The where clauses PARAM1 and PARAM2 are defined as VARCHAR type yet powerbuilder is somehow thinking that it is a NVARCHAR column. This is causing the bottleneck in our performance.
Is there a way of forcing powerbuilder to generate sql of type varchar instead of nvarchar?
Edit:
I tried to run the above query in datastore to see if there would be any difference. It generates almost identical query and still suffers from the same problem. I'm guessing this problem isn't limited to embedded SQL only
Edit2:
Looking deeper into the problem, SQL Server's sp_executesql only accepts unicode types (ntext,nchar,nvarchar) as parameter, which is why I'm assuming powerbuilder defaults to nvarchar. So I guess my question now becomes how to prevent powerbuilder from using sp_executesql and use something else like EXECUTE(@SQL). Or any other ideas would be appreciated.