Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 try..catch statement

Author  Topic 

magdaf75
Starting Member

5 Posts

Posted - 2008-04-13 : 21:06:03
can someone help me how to corect the query,


BEGIN TRY
INSERT INTO ORDERS VALUES( 1122,'BAC123' );
INSERT INTO ORDLINE VALUES( 1122,991,1 );
PRINT 'VERY GOOD'
END TRY
BEGIN CATCH
PRINT 'FALSE'
INSERT INTO LOGTAB ('BAC123',1122,991,1, ERROR_NUMBER,ERROR_MESSAGE);
END CATCH


i am getting error:
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'ERROR_NUMBER'.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-13 : 23:31:46
quote:
Originally posted by magdaf75

can someone help me how to corect the query,


BEGIN TRY
INSERT INTO ORDERS VALUES( 1122,'BAC123' );
INSERT INTO ORDLINE VALUES( 1122,991,1 );
PRINT 'VERY GOOD'
END TRY
BEGIN CATCH
PRINT 'FALSE'
INSERT INTO LOGTAB VALUES('BAC123',1122,991,1, ERROR_NUMBER,ERROR_MESSAGE);
END CATCH


i am getting error:
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'ERROR_NUMBER'.


missed a VALUES clause in last insert
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-14 : 02:38:50
You also need to put the function paranthesises in the query.
BEGIN TRY

INSERT ORDERS
VALUES (
1122,
'BAC123'
)

INSERT ORDLINE
VALUES (
1122,
991,
1
)

PRINT 'VERY GOOD'
END TRY

BEGIN CATCH
PRINT 'FALSE'

INSERT LOGTAB
VALUES (
'BAC123',
1122,
991,
1,
ERROR_NUMBER(),
ERROR_MESSAGE()
)
END CATCH



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -