sql - Incorrect syntax near the keyword 'table' -


I'm getting this error what I'm doing is trying to get data from a table and a db and Keep it in another DB and table. The tables are not exactly the same, I am using a FETCH cursor, so I get the first line from the DB1 table and then keep each column value in the declared variable. Then I run an assembly statement in db2 table and get the next value. All of these are working properly because it runs properly, but in the end I get this error,

Wrong syntax near the keyword 'table'.

In the entire transaction details, an attempt / catch with the error of expression in the Cat block, apart from this, I do not know what is the reason for it.

Here is the code

  added to prevent additional result set at SET NOCOUNT - Interfering with the SELECT statement. Set nosenate on; TRY begin transaction sets ITENDITY column off --TURN identity_insert [dB] start [dbo] [TEST] all CONSTRAINTS table --TURN [dB] change [dbo] [TEST] NOCHECK barrier All -.... Insert statement here @ID whole process, @DT datetime, @PID varchar (10), select @AREA varchar (20) [ID] FETCH_TEST declare cursor [date], [PID], [Area] [OLDDB]. [DBO]. [Test] FETCH_TEST open as DB1; FETCH_TEST investigation @ID, @DT, @PID, fetching Next @AREA while @@ FETCH_STATUS = 0 start --INSTER value [dB] in the table INSERT INTO. [Dbo]. [TEST] ([ID], [DT], [PID], [field]) VALUES (@ID, @DT, @PID, @AREA) from FETCH_TEST investigation @ID, @DT, @PID, @AREA, finally Next Fetch; Close FETCH_TEST; DEALLOCATE FETCH_TEST; - If we arrive here, then success! Start the COMMIT end catch - oh, there was an error I @@ TRANCOUNT & gt; 0 ROLLBACK - exceptions declared @ErrMsg nvarchar (an error with 4000) details, @ErrSeverity integer selected @ErrMsg = ERROR_MESSAGE (), @ErrSeverity = ERROR_SEVERITY () RAISERROR (@ErrMsg, @ErrSeverity, 1) finally take hold - Turn off ITENDITY column set identity_insert [db]. [Dbo]. [TEST] Turning off all the CONSTRAINTS tables on the --TURN [DB]. [Dbo]. [TEST] Check restrictions end all  

The first thing is that @TRAIN_ID in your code Has never been declared

Scalar variables must be declared "@TRAIN_ID".

The other thing is that you do not need a cursor, instead what is wrong in the SET based operation? It will perform better !! [Db] [db]. Select [Test] ([ID], [DT], [PID], [Area]) [ID], [date], [PID], [area] to [OLDDB]. [DBO]. [Test] dB as 1

You have an extra comma

  FETCH NEXT FETCH_TEST @ID, @DT, @PID from, @AREA,  

should be

  FETCH FETCH_TEST further than INTO @ ID, @DT, PID, @RAEA  
< P> But as I said you do not need a cursor for it


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -