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. i m new in sql.i want print a message(the table employe is not exist in database) in error handling with try and catch

i m new in sql.i want print a message(the table employe is not exist in database) in error handling with try and catch

Scheduled Pinned Locked Moved Database
databasesharepointhelp
4 Posts 3 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.
  • R Offline
    R Offline
    Rashid Choudhary
    wrote on last edited by
    #1

    my query is
    <pre lang="SQL">create proc sp_emprecord
    as begin
    select * from employe
    end
    begin try
    execute sp_emprecord
    end try

      begin catch
      select
      error\_message() as errormessage,
      error\_number() as erronumber,
      error\_state() as errorstate,
      error\_procedure() as errorprocedure,
      error\_line() as errorline;
      end catch</pre>
    
    L P 3 Replies Last reply
    0
    • R Rashid Choudhary

      my query is
      <pre lang="SQL">create proc sp_emprecord
      as begin
      select * from employe
      end
      begin try
      execute sp_emprecord
      end try

        begin catch
        select
        error\_message() as errormessage,
        error\_number() as erronumber,
        error\_state() as errorstate,
        error\_procedure() as errorprocedure,
        error\_line() as errorline;
        end catch</pre>
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You have already asked this vague question in QA

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

      1 Reply Last reply
      0
      • R Rashid Choudhary

        my query is
        <pre lang="SQL">create proc sp_emprecord
        as begin
        select * from employe
        end
        begin try
        execute sp_emprecord
        end try

          begin catch
          select
          error\_message() as errormessage,
          error\_number() as erronumber,
          error\_state() as errorstate,
          error\_procedure() as errorprocedure,
          error\_line() as errorline;
          end catch</pre>
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Use Raiserror[^] with a security-level lower than 20.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • R Rashid Choudhary

          my query is
          <pre lang="SQL">create proc sp_emprecord
          as begin
          select * from employe
          end
          begin try
          execute sp_emprecord
          end try

            begin catch
            select
            error\_message() as errormessage,
            error\_number() as erronumber,
            error\_state() as errorstate,
            error\_procedure() as errorprocedure,
            error\_line() as errorline;
            end catch</pre>
          
          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          That's probably not worth the effort; just catch the Exception in the calling code. And don't prefix your procedures with sp_ -- that's for System Procedures.

          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