关于SQL 建立存储过程!急急急!

IVY_AI3 2013-05-19 10:51:39
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
-- Add the parameters for the stored procedure here
<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO




在上面的模板中,如何创建存储过程。。。。求教。。。

要求是:1建立表1保存职员基本信息;
2 建立表2保存操作人员姓名及密码;
3 建立存储过程1用于填充下拉列表框(窗体中有combobox);
4建立存储过程2用于判断操作员及密码;
5建立存储过程3用于统计男女职员人数

表我已经建好了 就是不知道怎么写存储过程的那个代码 麻烦各位在上面的模板中教我怎么写吧 拜托了。。。[
img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif][/img]
...全文
337 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
乡下程序员 2013-06-10
  • 打赏
  • 举报
回复
问题应该解决了吧?~ 我也刚写了一篇存储过程的,分享下 http://blog.csdn.net/wowkk/article/details/9070339
qccxy 2013-06-08
  • 打赏
  • 举报
回复
3 建立存储过程1用于填充下拉列表框(窗体中有combobox); 存储过程能填充窗体中的下拉列表??
铁歌 2013-06-08
  • 打赏
  • 举报
回复
-- ================================================
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author: iamdba tim wang
 -- Create date: 2013-6-20
 -- Description:  用于统计男女职员人数


 -- =============================================
 create PROCEDURE usp_employeesCount
@resultCnt_male int output,
@resultCnt_female int output
 AS
 BEGIN
 
	SET NOCOUNT ON;
 
    
	select @resultCnt_male =COUNT(*) 
	from	dbo.t
	where sex =1   --sex :性别列 1为male 0为femail

	select @resultCnt_female =COUNT(*) 
	from
	dbo.t
	where sex =0
	
	 
 END
 GO

declare @resultf int,@resultm int --变量判断是否
exec usp_employeesCount @resultOut=@resultCnt_male  output, @resultm = @resultCnt_female output
select @resultf as femalcount,@resultm as malecount

print @resultOut
daiyueqiang2045 2013-05-21
  • 打赏
  • 举报
回复
lz刚入门不要太心急而只是去完成老师的任务。这不是最终目的。 你的最终目的是学到东西,建议lz看一些sql方面的教程
IVY_AI3 2013-05-21
  • 打赏
  • 举报
回复
引用 4 楼 daiyueqiang 的回复:
lz刚入门不要太心急而只是去完成老师的任务。这不是最终目的。 你的最终目的是学到东西,建议lz看一些sql方面的教程
我是想好好學這個啊 可是老師的任務也必須在規定時間內完成 這個禮拜又有其他的考試 真的沒辦法去好好看書啊
daiyueqiang2045 2013-05-20
  • 打赏
  • 举报
回复
lz 你的这个问题真心的很基础。建议你按F1查看帮助。 不过给你举一个很简单的例子(关于判断操作员及密码)。
-- ================================================
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author: daiyueqiang
 -- Create date: 2013-5-20
 -- Description: 判断是否存在用户名和密码是否正确
 -- =============================================
 create PROCEDURE sp_IsCanLogin
@name varchar(20),
@password varchar(20),
@resultOut int output
 AS
 BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
	SET NOCOUNT ON;
 
    -- Insert statements for procedure here
	select @resultOut=COUNT(*) --top 1 @resultOut=主键ID
	from
	dbo.t
	where name=@name and name=@password
	
	return @resultOut;
 END
 GO

declare @resultOut int --变量判断是否
exec sp_IsCanLogin @name='1', @password='22',@resultOut=@resultOut output

print @resultOut
IVY_AI3 2013-05-20
  • 打赏
  • 举报
回复
引用 1 楼 daiyueqiang 的回复:
lz 你的这个问题真心的很基础。建议你按F1查看帮助。 不过给你举一个很简单的例子(关于判断操作员及密码)。
-- ================================================
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author: daiyueqiang
 -- Create date: 2013-5-20
 -- Description: 判断是否存在用户名和密码是否正确
 -- =============================================
 create PROCEDURE sp_IsCanLogin
@name varchar(20),
@password varchar(20),
@resultOut int output
 AS
 BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
	SET NOCOUNT ON;
 
    -- Insert statements for procedure here
	select @resultOut=COUNT(*) --top 1 @resultOut=主键ID
	from
	dbo.t
	where name=@name and name=@password
	
	return @resultOut;
 END
 GO

declare @resultOut int --变量判断是否
exec sp_IsCanLogin @name='1', @password='22',@resultOut=@resultOut output

print @resultOut
留个QQ号吧 2298368142 真心刚入门 SQL语言都还没搞清楚是什么东东 老师就让做头疼的实验。。。。。希望你可以联系我 尽快帮我解决这个问题啊 拜托拜托了
IVY_AI3 2013-05-20
  • 打赏
  • 举报
回复
引用 1 楼 daiyueqiang 的回复:
lz 你的这个问题真心的很基础。建议你按F1查看帮助。 不过给你举一个很简单的例子(关于判断操作员及密码)。
-- ================================================
 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 -- =============================================
 -- Author: daiyueqiang
 -- Create date: 2013-5-20
 -- Description: 判断是否存在用户名和密码是否正确
 -- =============================================
 create PROCEDURE sp_IsCanLogin
@name varchar(20),
@password varchar(20),
@resultOut int output
 AS
 BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
	SET NOCOUNT ON;
 
    -- Insert statements for procedure here
	select @resultOut=COUNT(*) --top 1 @resultOut=主键ID
	from
	dbo.t
	where name=@name and name=@password
	
	return @resultOut;
 END
 GO

declare @resultOut int --变量判断是否
exec sp_IsCanLogin @name='1', @password='22',@resultOut=@resultOut output

print @resultOut
额 然后是不是要在SQL里选择调试执行?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧