function in storeed procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridhar21
    New Member
    • Feb 2007
    • 26

    function in storeed procedure

    hi to all

    i am sridhar

    i need a simple example for all type of function in stored procedure

    thanxs
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,
    here is the example for functions in Sql

    Create function functionname(pa rameter1 datatype1,param eter2 datatype2 out)
    returns datatype
    as

    --Here comes your declaration and code part
    Declare @v1 int;
    set @v1=0;
    return @v1
    End

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by sridhar21
      hi to all

      i am sridhar

      i need a simple example for all type of function in stored procedure

      thanxs
      Hi there Sridhar,

      What language are you using?

      Here is an example of a function using VB.NET and store procedures:
      Code:
      Public Function FooBar(ByRef newUserID as String, ByRef newUserPswHash) As Boolean
           Dim sqlcom As New SqlCommand
           Dim res As Boolean = False
           sqlcom.CommandType = CommandType.StoredProcedure
      
           'Indicating which store procedure to use by supplying the sqlcom.CommandText with the store procedure's name
           sqlcom.CommandText = "add_user"
      
           'Adding the parameters the store procedure is expecting
           sqlcom.Parameters.Add("@u_id", SqlDbType.VarChar, 15).Value = newUserID
           sqlcom.Parameters.Add("@u_passwordHash", SqlDbType.VarChar, 40).Value = newUserPswHash
      
           'Setting the sqlcom.Connection to a pre-defined connection
           sqlcom.Connection = Connection
      
           Try
                res = (sqlcom.ExecuteNonQuery()=1)
           Catch ex As Exception
                res = False
           End Try
      
           Return res
      
      End Function
      Hope this helps

      -Frinny

      Comment

      Working...