正文

存储过程2006-11-23 20:50:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/jixian/20685.html

分享到:

(1)--向表中添加一个字段

use tep
go

create proc addd
@idd int,
@name char,
@cityy char,
@phonee int,
@faxx int
as
declare @iddd int
declare @namee char
declare @cityyy char
declare @phoneee int
declare @faxxx int

set @iddd=@idd  
set @namee=@name
set @cityyy=@cityy
set @phoneee=@phonee
set @faxxx=@faxx

insert into customers

values(@iddd,@namee,@cityyy,@phoneee,@faxxx)
go

 

注释:

set @iddd=@idd  
set @namee=@name
set @cityyy=@cityy
set @phoneee=@phonee
set @faxxx=@faxx

set 后不能有逗号“,”

或者这几个语句改为:

select @iddd=@idd,
 @namee=@name,
 @cityyy=@cityy,
 @phoneee=@phonee,
 @faxxx=@faxx

select 后有逗号

 declare @iddd int
declare @namee char
declare @cityyy char
declare @phoneee int
declare @faxxx int

 

或者

declare @iddd int,
@namee char,
 @cityyy char,
 @phoneee int,
 @faxxx int

 注意逗号

 (2) 更新表inventory

create proc prUpdateStatus
@inventoryid int,
@statusid int
as
update inventory
set statusid=@statusid
where inventoryid=@inventoryid

(3)多表查询

create procedure prListProperties
@inventoryid int
as

select property.property property,
inventoryproperty.value value,
property.unit unit
from inventoryproperty join property
on inventoryproperty.propertyid=property.propertyid
where inventoryproperty.inventoryid=@inventoryid
go

语法:
Select tableA.a,b,c

From tableA,tableB

Where tableA.a=tableB.a

当两表有相同列名时,需在元素前加表名 tableA.a 。。。

单表内的模拟多表查询:

Select first.a,second.a

From tableA first,tableA second

Where first.b = second.f

(4)带返回值

create proc prGetLeaseScheduleID
@InventoryId int,
@LeaseScheduleId int output
as
select @LeaseScheduleId=LeaseScheduleId
from inventory
where inventoryid=inventoryid

declare @result int
exec prgetleasescheduleid
@leasescheduleid=@result output,    --不要写反,跟其他语言有所不同,赋值
@inventoryid=121

select @result result
 

阅读(2804) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册