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.
| Author |
Topic |
|
lfmn
Posting Yak Master
141 Posts |
Posted - 2002-06-27 : 16:44:20
|
| when I run the following statement:insert authors (au_id)values ('172-32-1176')I get the following error:Server: Msg 515, Level 16, State 2, Line 1Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.The statement has been terminated.does anyone know how to capture the text of the error into a variable so I can insert it into a table?SQL is useful if you don't know cursors :-) |
|
|
Glockenspiel
Yak Posting Veteran
50 Posts |
Posted - 2002-06-27 : 17:01:10
|
| You mean something like this?begin INSERT authors (au_id) values ('172-32-1176') SELECT description FROM master..sysmessages WHERE error = @@ERRORend |
 |
|
|
VyasKN
SQL Server MVP & SQLTeam MVY
313 Posts |
Posted - 2002-06-27 : 17:10:05
|
| You can not access the actual error message from within T-SQL. I discussed this at:http://vyaskn.tripod.com/programming_faq.htm#q7http://vyaskn.tripod.com/programming_faq.htm#q11--HTH,Vyashttp://vyaskn.tripod.com |
 |
|
|
lfmn
Posting Yak Master
141 Posts |
Posted - 2002-06-28 : 07:59:47
|
If you run this code, you get the following results:Cannot insert the value NULL into column '%.*ls', table '%.*ls'; column does not allow nulls. %ls fails.which doesn't give you the table or column or which operation failed.quote: You mean something like this?begin INSERT authors (au_id) values ('172-32-1176') SELECT description FROM master..sysmessages WHERE error = @@ERRORend
SQL is useful if you don't know cursors :-) |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-06-28 : 08:44:03
|
| This question has been posed before, I believe nr has a good solution.Jonathan Boott, MCDBA |
 |
|
|
|
|
|