日期:2014-05-18 浏览次数:20638 次
--> 测试数据:[test]
if object_id('[test]') is not null
drop table [test]
create table [test](
stuno int,
stuname varchar(4),
stuage int,
stusex tinyint,
stutel bigint,
stuaddress varchar(6)
)
insert [test]
select 1,'张三',20,1,13456780990,'沙坪坝' union all
select 2,'李四',20,1,13456780990,'沙坪坝' union all
select 3,'王五',20,1,13456780990,'开发区' union all
select 4,'美女',19,0,13256357854,'沙坪坝'
if OBJECT_ID('proc_GetStuInfo')is not null
drop proc proc_GetStuInfo
go
create proc proc_GetStuInfo @address nvarchar(20)
as
select
stuno as [学号],
stuname as [姓名],
stuage as [年龄],
case when stusex=1 then '男' else '女' end as [性别],
stutel as [电话],
stuaddress as [地址]
from
[test]
where
stuaddress=@address
go
--掉用存储过程:
exec proc_GetStuInfo '沙坪坝'
/*
学号 姓名 年龄 性别 电话 地址
---------------------------------------------------
1 张三 20 男 13456780990 沙坪坝
2 李四 20 男 13456780990 沙坪坝
4 美女 19 女 13256357854 沙坪坝
*/