I seem to have gotten myself into a bit of a tangle with this bit of dynamic sql. Can anyone look at it with fresh eyes and clear it up for me?
The statement is stored in a table as a string. It's actaully a string that runs against a Postgres database using OPENQUERY. The table is read and each statement executed in turn.
My statement needs to have a series of ' (single quote) in it. My problem is I can't work out how many I need and where for it to execute properly.
The 'complied' version should be:
This works fine when I run it on the Postgres box. Obviously when I run it from SQL I have it as a string to pass to OPENQUERY. This is where my problem comes. I can't get the right mix of single quotes to force SQL to pass the correct string to Postgres.
Any help would be appreciated. I've been staring at this for absolutely ages now.
Thanks folks.
The statement is stored in a table as a string. It's actaully a string that runs against a Postgres database using OPENQUERY. The table is read and each statement executed in turn.
My statement needs to have a series of ' (single quote) in it. My problem is I can't work out how many I need and where for it to execute properly.
The 'complied' version should be:
Code:
select id, trim(leading '<searchdate>' from substring(demographicdata from POSITION('<searchdate>' IN demographicdata) for POSITION('<searchdate>'
IN demographicdata)-POSITION('<searchdate>' IN demographicdata))) as searchdate from xmltable
This works fine when I run it on the Postgres box. Obviously when I run it from SQL I have it as a string to pass to OPENQUERY. This is where my problem comes. I can't get the right mix of single quotes to force SQL to pass the correct string to Postgres.
Any help would be appreciated. I've been staring at this for absolutely ages now.
Thanks folks.