create function fun(@id int)
returns table
as
return (select name from students where id=@id)
//How to use in sql server
select * from master.dbo.fun(1);
////how to use in asp.net
con.open();
SqlCommand cmd = new SqlCommand("select name from schools.dbo.fun(3)", con);
SqlDataReader dr2 = cmd.ExecuteReader();
if (dr2.HasRows)
{
while (dr2.Read())
{
string s= dr2.GetString(0);
}
}
con.close();
///another Function return string
CREATE FUNCTION GetFullName()
RETURNS varchar(100)
AS
BEGIN
RETURN 'Doe, John'
END
//how to use function in sql server
PRINT Schools.dbo.GetFullName();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment