Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
@@Error
Message
 
À
12/04/2006 16:48:17
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01113074
Message ID:
01113167
Vues:
10
This "works" :o)) I get Failed

>Borislav,
>
>Try this:
>
drop table bugs
>create table bugs ( bugid int primary key)
>
>declare @Err int
>
>INSERT INTO bugs(BugId) values (123)
>INSERT INTO bugs(BugId) values (123)
>IF @@Error <> 0	
>	Print 'Failed'
>ELSE
>	Print 'OK'	
>
>
>>Here the SP i use for tests:
>>
>>ALTER PROCEDURE [dbo].[Test1]
>>AS
>>SET NOCOUNT OFF
>>INSERT INTO bugs(BugId) values ('sdf')
>>IF @@error <> 0
>>   Print 'Failed'
>>ELSE
>>   Print 'OK'	
>>
>>BugId is integer.
>>When I execute it I got this:
>>
>>Msg 245, Level 16, State 1, Procedure Test1, Line 5
>>Conversion failed when converting the varchar value 'sdf' to data type int.
>>
>>
>>But when I change it to:
>>
>>ALTER PROCEDURE [dbo].[Test1]
>>AS
>>SET NOCOUNT OFF
>>INSERT INTO bugs(BugId) values (9999999999)
>>IF @@error <> 0
>>   Print 'Failed'
>>ELSE
>>   Print 'OK'	
>>
>>I got:
>>
>>Msg 248, Level 16, State 1, Procedure Test1, Line 5
>>The conversion of the varchar value '9999999999' overflowed an int column. Maximum integer value exceeded.
>>The statement has been terminated.
>>Failed
>>
>>
>>Maybe, some errors are more fatal than other, but I don't know how to define, becuase both errors have same severity - 16
>>
>>
>>
>>>Here is my stored procedure
>>>
>>>DECLARE @ErrorInsert int, @ErrorUpdate int,
>>>
>>>INSERT INTO [111.11.1.11,1433].ipo.dbo.ui_userlookup
>>>	SELECT * FROM OPENQUERY(ADSI, 'SELECT ciscoEcsbuDtmfID, department, ciscoEcsbuDtmfID, mail, title, cn, SAMAccountName
>>>		FROM ''LDAP://DC=something,DC=something''
>>>		WHERE objectCategory = ''Person''
>>>		AND objectclass = ''user''
>>>		AND title = ''Instrument Specialist*''
>>>		AND numberrestrictiongroup <> ''*removed*''
>>>		AND (accountexpires = 9223372036854775807 OR accountexpires = 0)
>>>		ORDER BY cn ')
>>>
>>>SELECT @ErrorInsert = @@Error
>>>
>>>UPDATE [111.11.1.11,1433].ipo.dbo.ui_userlookup
>>>	SET cusertype = 'IS' WHERE cusertype = cphoneext
>>>
>>>SELECT @ErrorUpdate = @@Error
>>>
>>>
>>>IF @ErrorInsert <> 0 OR @ErrorUpdate <> 0
>>>	BEGIN	
>>>
>>>		--send an email using exec master.dbo.xp_smtp_sendmail
>>>	END
>>>
>>>
>>>When there is a problem with the insert statment the @@error is not being assigned and program never gets to the if statement.
>>>
>>>Daniel
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform