This is the senario, i am trying to copy a table and store that table into a XML variable(Not physically xml file) and read that XML variable ,at the same time also trying to retrive and insert all data to another table.The stored procedure is given below
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Thabo
-- Create date: 18.02.2011
-- Description: TEST XML
-- =============================================
CREATE PROCEDURE sppassingStoredProcedue
DECLARE @x XML
AS
BEGIN
SET NOCOUNT ON;
SET @x=(SELECT PramryKeyForThisTable,AutoNumberColumn,Data1,Data2,Data3 FROM tblInsertTableForAutoNumber FOR XML AUTO ,TYPE ,ELEMENTS XSINIL,ROOT ('TABLEROOT'))
INSERT INTO CopyOftblInserTableForAutonumber
SELECT
tab.col.value('@PrimaryKeyForThisTable[1]','SMALLINT') AS PramryKeyForThisTable,
tab.col.value('@AutoNumberColumn[1]','SMALLINT')AS AutoNumberColumn,
tab.col.value('@Data1[1]','VARCHAR(50)') AS Data1,
tab.col.value('@Data2[1]','VARCHAR(50)') AS Data2,
tab.col.value('@Data3[1]','VARCHAR(50)') AS Data3
FROM @x.nodes('//TABLEROOT/tblInsertTableForAutoNumber')AS tab(Col)
END
Actually the second table is the copy of the first table.It has same stucure of the first table The table structure is, colum name datatype ----------- -------- PramryKeyForThisTable smallint AutoNumberColumn smallint Data1 varchar(50) Data2 varchar(50) Data3 varchar(50) I have got different different error messages every time.i hve got this error message for above cording.
Msg 156, Level 15, State 1, Procedure sppassingStoredProcedue, Line 7
Incorrect syntax near the keyword 'DECLARE'.
Msg 156, Level 15, State 1, Procedure sppassingStoredProcedue, Line 8
Incorrect syntax near the keyword 'AS'."
I couldnt figure out how to do this. Can any one pls give a good solution for this. Thabo
-- Modified Friday, February 18, 2011 11:33 AM