473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

function in storeed procedure

hi to all

i am sridhar

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

thanxs
Feb 28 '07 #1
2 1058
shweta123
692 Expert 512MB
Hi,
here is the example for functions in Sql

Create function functionname(parameter1 datatype1,parameter2 datatype2 out)
returns datatype
as

--Here comes your declaration and code part
Declare @v1 int;
set @v1=0;
return @v1
End
Feb 28 '07 #2
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function FooBar(ByRef newUserID as String, ByRef newUserPswHash) As Boolean
  2.      Dim sqlcom As New SqlCommand
  3.      Dim res As Boolean = False
  4.      sqlcom.CommandType = CommandType.StoredProcedure
  5.  
  6.      'Indicating which store procedure to use by supplying the sqlcom.CommandText with the store procedure's name
  7.      sqlcom.CommandText = "add_user"
  8.  
  9.      'Adding the parameters the store procedure is expecting
  10.      sqlcom.Parameters.Add("@u_id", SqlDbType.VarChar, 15).Value = newUserID
  11.      sqlcom.Parameters.Add("@u_passwordHash", SqlDbType.VarChar, 40).Value = newUserPswHash
  12.  
  13.      'Setting the sqlcom.Connection to a pre-defined connection
  14.      sqlcom.Connection = Connection
  15.  
  16.      Try
  17.           res = (sqlcom.ExecuteNonQuery()=1)
  18.      Catch ex As Exception
  19.           res = False
  20.      End Try
  21.  
  22.      Return res
  23.  
  24. End Function
  25.  
Hope this helps

-Frinny
Feb 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mariusz | last post by:
I want to write function to call another function which name is parameter to first function. Other parameters should be passed to called function. If I call it function('f1',10) it should call...
1
by: Fran?ois Bourdages | last post by:
Hi is there a way to know if object (view, function, etc) are invalid ? let say a have a table t1 (field col1, col2) and a view v1 (field t1.col1, t1.col2) if I drop t1.col2, the view v1 is not...
6
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
4
by: Chris Auer | last post by:
What I am looking to do is use a complicated stored procedure to get data for me while in another stored procedure. Its like a view, but a view you can't pass parameters to. In essence I would...
8
by: WindAndWaves | last post by:
Hi everyone Why do you use the word public in a function, when the function is fully accessible without the word public in front of it. I read the help, but did not really get it. Cheers ...
4
by: Steve D | last post by:
Does anyone know if this can be done?
14
by: digital | last post by:
hello anyone... pls explain me , how different between function and procedure for C/C++ and Pascal. Thankx......
1
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.