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. Check for Null or Empty In SP

Check for Null or Empty In SP

Scheduled Pinned Locked Moved Database
sharepointdatabasehelpquestion
6 Posts 5 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.
  • S Offline
    S Offline
    siva455
    wrote on last edited by
    #1

    Hi, Please let me know how can i check whether the i/p parameters were Null or empty and raise error and let user know that particular parameter is null or empty when he is trying to execute the SP (Stored procedure)....

    W P G 4 Replies Last reply
    0
    • S siva455

      Hi, Please let me know how can i check whether the i/p parameters were Null or empty and raise error and let user know that particular parameter is null or empty when he is trying to execute the SP (Stored procedure)....

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      You mean inside the stored procedure? You can use IS NULL operator:

      create procedure foo @param1 decimal as
      begin
      if @param1 is null
      begin
      raiserror('param1 is null', 16, 1);
      end;
      end;

      exec foo 1;

      exec foo null;

      The need to optimize rises from a bad design.My articles[^]

      R 1 Reply Last reply
      0
      • S siva455

        Hi, Please let me know how can i check whether the i/p parameters were Null or empty and raise error and let user know that particular parameter is null or empty when he is trying to execute the SP (Stored procedure)....

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Yes, what Mika said, but you're still better off wrapping a Data Access Layer around your database to check things like that.

        1 Reply Last reply
        0
        • W Wendelius

          You mean inside the stored procedure? You can use IS NULL operator:

          create procedure foo @param1 decimal as
          begin
          if @param1 is null
          begin
          raiserror('param1 is null', 16, 1);
          end;
          end;

          exec foo 1;

          exec foo null;

          The need to optimize rises from a bad design.My articles[^]

          R Offline
          R Offline
          Rakesh Meel
          wrote on last edited by
          #4

          create procedure Myproc @myvar1 decimal as begin if @myvar1 is null begin error('@myvar1 is null', 16, 1); end; end;

          1 Reply Last reply
          0
          • S siva455

            Hi, Please let me know how can i check whether the i/p parameters were Null or empty and raise error and let user know that particular parameter is null or empty when he is trying to execute the SP (Stored procedure)....

            G Offline
            G Offline
            Ganu Sharma
            wrote on last edited by
            #5

            You can check your parameter is null or empty. there are various way in sql server or oracle database. declare @IP NVARCHAR(SIZE) IF(@IP IS NULL OR @IP = '') BEGIN SQL STATEMENTS. END ELSE BEGIN SQL STATEMENTS. END IF(@@ERROR > 0) SQL STATEMENTS. :) :)

            1 Reply Last reply
            0
            • S siva455

              Hi, Please let me know how can i check whether the i/p parameters were Null or empty and raise error and let user know that particular parameter is null or empty when he is trying to execute the SP (Stored procedure)....

              G Offline
              G Offline
              Ganu Sharma
              wrote on last edited by
              #6

              Hi.. check your parameter is null or not. in stored procedure if(parameter is null or parameter ='') begin sql statements end else begin sql statements end or in single query. select * from tbl where parameter is null or parameter =''

              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