Pass variable to a user-defined function : Variable « Transact SQL « SQL Server / T-SQL Tutorial






6> CREATE FUNCTION dbo.ufnIsOdd (@n int)
7> RETURNS bit
8> AS
9> BEGIN
10>     RETURN (@n % 2)
11> END
12> GO
1>
2> DECLARE @numb int
3> SET @numb = 6
4> SELECT @numb 'Number', dbo.ufnIsOdd (@numb) 'Is_odd = 1'
5> SET @numb = 7
6> SELECT @numb 'Number', dbo.ufnIsOdd (@numb) 'Is_odd = 1'
7> GO
Number      Is_odd = 1
----------- ----------
          6          0

(1 rows affected)
Number      Is_odd = 1
----------- ----------
          7          1

(1 rows affected)
1>








20.2.Variable
20.2.1.Working with Variables
20.2.2.Use right function with a variable
20.2.3.Testing the ISNULL function
20.2.4.SELECT LEFT(@FullName, 5)
20.2.5.Global variable names begin with an @@ prefix.
20.2.6.XML type variable
20.2.7.Varchar type variable
20.2.8.Use if statement to check a variable
20.2.9.A variable can be assigned a value from a subquery
20.2.10.Use aggregate function with variables
20.2.11.Use Local Variables in where clause
20.2.12.A SQL script that uses variables
20.2.13.Local variables used for searches
20.2.14.Pass variable to a user-defined function
20.2.15.Use one variables in like function