Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Why @@Error Is not Working

Why @@Error Is not Working

Scheduled Pinned Locked Moved Database
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amit Kumar G
    wrote on last edited by
    #1

    I have simple situation...Here explicitly i am trying to insert char instead of integer and want to throw exception. But instead of printing "a" i am getting "Conversion failed when converting the varchar value 'a' to data type int." .... ANY REASONS WHY??? CREATE TABLE Temp(C Int) GO INSERT INTO Temp VALUES('a') IF @@ERROR <> 0 BEGIN print 'a' END Amit

    F 1 Reply Last reply
    0
    • A Amit Kumar G

      I have simple situation...Here explicitly i am trying to insert char instead of integer and want to throw exception. But instead of printing "a" i am getting "Conversion failed when converting the varchar value 'a' to data type int." .... ANY REASONS WHY??? CREATE TABLE Temp(C Int) GO INSERT INTO Temp VALUES('a') IF @@ERROR <> 0 BEGIN print 'a' END Amit

      F Offline
      F Offline
      fasih1981
      wrote on last edited by
      #2

      Use this way to to do so: Declare @vError varchar(4000) Select @vError = convert( varchar,@@Error) IF @vError <> '0' GOTO ErrorHandler ErrorHandler: IF @vError = '0' BEGIN Commit Tran Return 0 -- On Success END Else BEGIN Rollback Tran Return @vError -- On failure END

      fasih_is_my_signature

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups