Tarun Sharma

Tarun Sharma

  • NA
  • 13
  • 2.3k

Need to Create temp table in ibatis

Jun 18 2018 11:36 PM
My project has some requirement to create temp table. I need to perform some operation on temp table like: -
1. Create table
2. Insert some data
3. Perform some operation on that data and update same.
4. Get that data from temp table.

I am able to perform all the operations while writing all queries in single statement, my sql mapper file look like this see below: -
<sqlMap namespace="xxx" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<select id="GetTempTableData" resultClass="xxx" parameterClass="System.String">
         Create table ##TestTable(MatterID varchar(20), ShortDesc varchar(100))
         Insert into ##TestTable values('1001-101','ABC')
         Insert into ##TestTable values('1001-102','XYZ')
         Select * from ##TestTable
</select>

</sqlMap>

But i have a requirement to split all queries into seprate sections, see below: -

<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="xxx" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<select id="GetTempTableData" resultClass="xxx" parameterClass="System.String">
         Create table ##TestTable(MatterID varchar(20), ShortDesc varchar(100))
</select>
<insert id="InsertIntoTempTable" resultClass="xxx" parameterClass="System.String">
         Insert into ##TestTable values('1001-101','ABC')
         Insert into ##TestTable values('1001-102','XYZ')
</insert>
<select id="SelectFromTempTable" resultClass="xxx" parameterClass="System.String">
         Select * from ##TestTable
</select>

</sqlMap>

But in 2nd approach i am getting exception "Invalid object name #TestTable".
Can someone please suggest me, what should i do in that case?
Quick solution will highly appreciated.

Thanks

Answers (1)