Unable to execute SQL Query using TI process.

Post Reply
ryan
Posts: 59
Joined: Thu May 26, 2011 5:04 am
OLAP Product: COGNOS
Version: 9.0
Excel Version: 2007

Unable to execute SQL Query using TI process.

Post by ryan »

I am unable to execute SQL Query using TI process.

I would like to insert a row in simple table.

Database: MS SQL Server (Quoted_Identifier is set OFF in MS SQL Server, in order to entertain double quotes)
Table Details:
Name: Table1
Element1: SNO (Int)
Element2: ENAME (VChar(10))
Element3: State (vChar(10))

What I want is:
1, 'Ryan', 'Victoria' to be inserted in the Table1

What I have done:
- Established ODBC Connectivity, I have tested and working fine, I could able to retrieve rows from the table to TM1 environment using the ODBC connectivity.

Code @ Data procedure tab (tried two ways):
#1
vSN = 1;
vEN = 'Ryan';
vSt = 'Victoria';

Query = Expand('Insert INTO Table1(SNO,ENAME,State) VALUES(%vSN% , "%vEN%" , "%vSt%")');
ODBCOutput(DSNName,Query);

Error: Error executing SQL query: "INSERT INTO Table1(SNO,ENAME,State) Values( 1.000,"Ryan","Victoria")"



#2
Query = Expand('Insert INTO Table1(SNO,ENAME,State) VALUES(%vSN% | ',' |vEN | ',' | vSt | ')');
ODBCOutput(DSNName,Query);

Error: Error executing SQL query: "INSERT INTO Table1(SNO,ENAME,State) Values( 1.000,Ryan,Victoria)"


None of the two query are eligible to run MS SQL Server environment as the string values are not enclosed with single quote(which is not possible in TM1). Is there any extra TI function that could turn double quote in to single quote?. Could anyone help me in running this query without fail? I appreciate your help.
Configuration Details
Microsoft Window Server 2003 Exterprise x64 Edition Service Pack 2
RAM 32 GB
using IBM Cognos Express Xcelerator (Version 10.1)
MS-Office Excel 2010 (12.0.6514.5000)SP2 MSO (12.0.6425.1000)
Microsoft .NET Framework 3.5
upali
Posts: 38
Joined: Thu Oct 11, 2012 6:15 am
OLAP Product: TM1
Version: 10.2.2.4
Excel Version: 2010
Location: Melbourne, Australia

Re: Unable to execute SQL Query using TI process.

Post by upali »

Use triple quotes

Code: Select all

Query = Expand('Insert INTO Table1(SNO,ENAME,State) VALUES(%vSN% | ',' '''|vEN |''' ',' '''| vSt |''' ')');
ryan
Posts: 59
Joined: Thu May 26, 2011 5:04 am
OLAP Product: COGNOS
Version: 9.0
Excel Version: 2007

Re: Unable to execute SQL Query using TI process.

Post by ryan »

upali wrote:Use triple quotes

Code: Select all

Query = Expand('Insert INTO Table1(SNO,ENAME,State) VALUES(%vSN% | ',' '''|vEN |''' ',' '''| vSt |''' ')');
oops.... not working.
Configuration Details
Microsoft Window Server 2003 Exterprise x64 Edition Service Pack 2
RAM 32 GB
using IBM Cognos Express Xcelerator (Version 10.1)
MS-Office Excel 2010 (12.0.6514.5000)SP2 MSO (12.0.6425.1000)
Microsoft .NET Framework 3.5
PlanningDev
Community Contributor
Posts: 349
Joined: Tue Aug 17, 2010 6:31 am
OLAP Product: Planning Analytics
Version: 2.0.5
Excel Version: 2016

Re: Unable to execute SQL Query using TI process.

Post by PlanningDev »

Concatenate using the char() function in TM1. Also, I dont think you need the expand function here. The variables should resolve unless there is some reason you are dynamically naming the variables.

Char(39) is for a single quote

Something along the lines of

Query = 'Insert INTO Table1(SNO,ENAME,State) VALUES( ' | NumberToString(vSN) | ', ' | CHAR(39) | vEN | CHAR(39) | ' , ' | CHAR(39) | vSt | CHAR(39) | ')';
User avatar
Michel Zijlema
Site Admin
Posts: 712
Joined: Wed May 14, 2008 5:22 am
OLAP Product: TM1, PALO
Version: both 2.5 and higher
Excel Version: 2003-2007-2010
Location: Netherlands
Contact:

Re: Unable to execute SQL Query using TI process.

Post by Michel Zijlema »

ryan wrote:
upali wrote:Use triple quotes

Code: Select all

Query = Expand('Insert INTO Table1(SNO,ENAME,State) VALUES(%vSN% | ',' '''|vEN |''' ',' '''| vSt |''' ')');
oops.... not working.
Please note (without looking more in-depth at your code) that you're putting a lot of quotes after each other: %vSN% | ',' '''|vEN |''' ',' '''| vSt.
Try %vSN% | ', ' | '''|vEN |''' | ', ' | '''| vSt or %vSN% | ', '''|vEN |''', '''| vSt instead.

Michel
Post Reply