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. Require StoredProc

Require StoredProc

Scheduled Pinned Locked Moved Database
sharepointhelp
5 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.
  • Y Offline
    Y Offline
    yadlaprasad
    wrote on last edited by
    #1

    Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc

    fttyhtrhyfytrytrysetyetytesystryrty

    B Y N 3 Replies Last reply
    0
    • Y yadlaprasad

      Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc

      fttyhtrhyfytrytrysetyetytesystryrty

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Here it is!

      create procedure InsertUser
      @username varchar(200)
      as
      Begin
      if(select count(*) from users where username=@username) = 0)
      begin

      insert into users values(column1,column2......)

      end
      end


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      1 Reply Last reply
      0
      • Y yadlaprasad

        Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc

        fttyhtrhyfytrytrysetyetytesystryrty

        Y Offline
        Y Offline
        yadlaprasad
        wrote on last edited by
        #3

        Hi , Thanks for reply in this stored proc i want to return some value. so that i can handle in my C# sharp code. i this case i want else condition and some return value

        fttyhtrhyfytrytrysetyetytesystryrty

        B 1 Reply Last reply
        0
        • Y yadlaprasad

          Hi , Thanks for reply in this stored proc i want to return some value. so that i can handle in my C# sharp code. i this case i want else condition and some return value

          fttyhtrhyfytrytrysetyetytesystryrty

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          Then I will suggest you to use function

          create function InsertUser
          @username varchar(200)
          as
          Begin

          return 0 --By default user is not inserted and return value have value 0

          if(select count(*) from users where username=@username) = 0)
          begin

          insert into users values(column1,column2......)
          return 1 --User is inserted and return value have value 1

          end

          end


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

          1 Reply Last reply
          0
          • Y yadlaprasad

            Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc

            fttyhtrhyfytrytrysetyetytesystryrty

            N Offline
            N Offline
            Niladri_Biswas
            wrote on last edited by
            #5

            Try this CREATE PROCEDURE [dbo].[USP_CheckUserAvailability] -- Add the parameters for the stored procedure here ( @UserName AS VARCHAR(50) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here IF EXISTS( SELECT [User Name] FROM tbl_User WHERE [User Name] = @UserName ) BEGIN SELECT * FROM tbl_User END ELSE INSERT INTO tbl_User ([User Name]) VALUES (@UserName) END Hope this helps :)

            Niladri Biswas

            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