创建有参数的存数过程,对比函数的定义而言,AS就相当于{},和函数一样,参数都定义在主体的前面
例如函数:
private static void Sum(double num1,double num2)
{
Console.WriteLine(num1+num2);
}
在调用的时候在
static void Main(string[] srgs)
{
Sum(3,4);
}
写就可以啦。
存储过程:
CREATE PROC Pro_GetNewsByTitle
@newskey VARCHAR(64)
AS
SELECT NewsTitle,SUBSTRING(NewsContent,1,20)+'...'
AS
NewsContent,CreateTime FROM T_News WHERE NewsTitle LIKE @newskey OR NewsContent LIKE @newskey
GO
测试:
EXEC Pro_GetNewsByTitle '%国%'
GO
带有输出参数的存储过程:
CREATE PROC Pro_GetMaxId
@newstitle VARCHAR(64),
@newscontent VARCHAR(MAX),
@newscreator VARCHAR(8),
@createtime DATETIME,
@classid uniqueidentifier,
@maxid INT OUT
AS
INSERT INTO T_News
(NewsTitle,NewsContent,NewsCreator,CreateTime,ClassId) VALUES
(@newstitle,@newscontent,@newscreator,@createtime,@classid);
SET @maxid=@@IDENTITY;
GO
测试:
DECLARE @maxid INT;
EXEC Proc_GetMaxId '11','111111','003','2012-02-02','b1babb97-cef5-4f07-8b77-b4560540acbd',@maxid out;
PRINT @maxid;
GO
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)