dbTalk Databases Forums  

MSSQL(Temp Table and sp_executesql) to DB2(problem)

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss MSSQL(Temp Table and sp_executesql) to DB2(problem) in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
scv1977
 
Posts: n/a

Default MSSQL(Temp Table and sp_executesql) to DB2(problem) - 04-26-2010 , 09:30 PM






Hi
Also conerting MSSQL to DB2(9.7),
We have problem...
I know ..
In the DB2(9.7), The MSSQL(sp_executesql) is possible to "execute
immediate"
But the following Query is possible??
The Logic is :
1) Create Temporary Table
2) Declare variable = 'alter table xxx'
3) Execute sp_executesql @variable

MSSQL)
DECLARE @docHandle INT,
@IntVariable INT,
@cCrTableSql NVARCHAR(MAX),
@cSchemaSql NVARCHAR(MAX),
@ParmDefinition NVARCHAR(500),
@ReplaceNm NVARCHAR(100),
@CommonCrTable NVARCHAR(1000),
@CommonHeader NVARCHAR(1000),
@pDataBlock NVARCHAR(100)

CREATE TABLE #TempTable (WorkingTag NCHAR(1) NULL)

SELECT @cCrTableSql = N'[CommonCrTable] alter table [DataBlock10] add
EmpSeq INT NULL alter table [DataBlock10] add SMAbrdName
NVARCHAR(100) NULL alter table [DataBlock10] add UMAbrdNationName
NVARCHAR(100) NULL alter table [DataBlock10] add TripArea
NVARCHAR(100) NULL alter table [DataBlock10] add TripRec
NVARCHAR(100) NULL alter table [DataBlock10] add DptDate NCHAR(8)
NULL alter table [DataBlock10] add ArvDate NCHAR(8) NULL ',
@cSchemaSql = N'INSERT INTO [DataBlock10]([CommonHeader],
EmpSeq, SMAbrdName, UMAbrdNationName, TripArea, TripRec, DptDate,
ArvDate) SELECT [CommonHeader], EmpSeq, SMAbrdName, UMAbrdNationName,
TripArea, TripRec, DptDate, ArvDate FROM OPENXML(@docHandle, N''/ROOT/
DataBlock10'', @xmlFlags) WITH [DataBlock10]'

SET @ReplaceNm = N'#TempTable'
SET @pDataBlock = N'DataBlock10'

SET @CommonCrTable = 'alter table '+'['+@pDataBlock+']' + ' add IDX_NO
INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add DataSeq INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Selected INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add MessageType INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Status INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Result NVARCHAR(255) NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add ROW_IDX INT NULL '

SET @cCrTableSql = REPLACE(@cCrTableSql, '[CommonCrTable]',
@CommonCrTable)

SET @cCrTableSql = REPLACE(@cCrTableSql, '['+@pDataBlock+']',
@ReplaceNm)

SET @ParmDefinition = N'@docHandle int OUTPUT'

EXECUTE sp_executesql @cCrTableSql, @ParmDefinition,
@docHandle OUTPUT

SELECT * FROM #TempTable

DROP TABLE #TempTable

Reply With Quote
  #2  
Old   
Serge Rielau
 
Posts: n/a

Default Re: MSSQL(Temp Table and sp_executesql) to DB2(problem) - 04-27-2010 , 11:29 PM






On 4/27/2010 8:00 AM, scv1977 wrote:
Quote:
Hi
Also conerting MSSQL to DB2(9.7),
We have problem...
I know ..
In the DB2(9.7), The MSSQL(sp_executesql) is possible to "execute
immediate"
But the following Query is possible??
The Logic is :
1) Create Temporary Table
2) Declare variable = 'alter table xxx'
3) Execute sp_executesql @variable

MSSQL)
DECLARE @docHandle INT,
@IntVariable INT,
@cCrTableSql NVARCHAR(MAX),
@cSchemaSql NVARCHAR(MAX),
@ParmDefinition NVARCHAR(500),
@ReplaceNm NVARCHAR(100),
@CommonCrTable NVARCHAR(1000),
@CommonHeader NVARCHAR(1000),
@pDataBlock NVARCHAR(100)

CREATE TABLE #TempTable (WorkingTag NCHAR(1) NULL)

SELECT @cCrTableSql = N'[CommonCrTable] alter table [DataBlock10] add
EmpSeq INT NULL alter table [DataBlock10] add SMAbrdName
NVARCHAR(100) NULL alter table [DataBlock10] add UMAbrdNationName
NVARCHAR(100) NULL alter table [DataBlock10] add TripArea
NVARCHAR(100) NULL alter table [DataBlock10] add TripRec
NVARCHAR(100) NULL alter table [DataBlock10] add DptDate NCHAR(8)
NULL alter table [DataBlock10] add ArvDate NCHAR(8) NULL ',
@cSchemaSql = N'INSERT INTO [DataBlock10]([CommonHeader],
EmpSeq, SMAbrdName, UMAbrdNationName, TripArea, TripRec, DptDate,
ArvDate) SELECT [CommonHeader], EmpSeq, SMAbrdName, UMAbrdNationName,
TripArea, TripRec, DptDate, ArvDate FROM OPENXML(@docHandle, N''/ROOT/
DataBlock10'', @xmlFlags) WITH [DataBlock10]'

SET @ReplaceNm = N'#TempTable'
SET @pDataBlock = N'DataBlock10'

SET @CommonCrTable = 'alter table '+'['+@pDataBlock+']' + ' add IDX_NO
INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add DataSeq INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Selected INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add MessageType INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Status INT NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add Result NVARCHAR(255) NULL '
SET @CommonCrTable = @CommonCrTable + ' alter table '+'['+@pDataBlock
+']' + ' add ROW_IDX INT NULL '

SET @cCrTableSql = REPLACE(@cCrTableSql, '[CommonCrTable]',
@CommonCrTable)

SET @cCrTableSql = REPLACE(@cCrTableSql, '['+@pDataBlock+']',
@ReplaceNm)

SET @ParmDefinition = N'@docHandle int OUTPUT'

EXECUTE sp_executesql @cCrTableSql, @ParmDefinition,
@docHandle OUTPUT

SELECT * FROM #TempTable

DROP TABLE #TempTable
DB2 supports EXECUTE IMMEDIATE directly. No need to go through an procedure.
But in DB2 you want to execute each ALTER TABLE individually (don't
batch them up).

So:
EXECUTE IMMEDIATE 'ALTER TABLE ....' ;
EXECUTE IMMEDIATE '...';
and so forth



--
Serge Rielau
SQL Architect DB2 for LUW
IBM Toronto Lab

Reply With Quote
  #3  
Old   
scv1977
 
Posts: n/a

Default Re: MSSQL(Temp Table and sp_executesql) to DB2(problem) - 04-28-2010 , 01:30 AM



Is possible EXECUTE IMMEDIATE 'ALTER TABLE GTE(global temp table)'
If not support, Are there other ways to handle "alter table GTE"

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.