首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

小弟我是新手 帮忙解一下

2012-05-21 
我是新手 帮忙解一下啊创建一个存储过程proc_GetStuInfo,输入参数为@Address,根据地址查询学生信息。将表头

我是新手 帮忙解一下啊
创建一个存储过程proc_GetStuInfo,输入参数为@Address,根据地址查询学生信息。将表头显示为中文,将性别“0”或“1”转换为“男”或“女”显示出来。如下图所示

  学号 姓名 年龄 性别 电话 住址
1 1 张三 20 男 13456780990 沙坪坝
2 2 美女 19 女 13256357854 沙坪坝

[解决办法]

SQL code
--> 测试数据:[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 allselect 2,'李四',20,1,13456780990,'沙坪坝' union allselect 3,'王五',20,1,13456780990,'开发区' union allselect 4,'美女',19,0,13256357854,'沙坪坝'if OBJECT_ID('proc_GetStuInfo')is not nulldrop proc proc_GetStuInfogocreate proc proc_GetStuInfo @address nvarchar(20)asselect      stuno as [学号],     stuname as [姓名],     stuage as [年龄],     case when stusex=1 then '男' else '女' end as [性别],     stutel as [电话],     stuaddress as [地址]from     [test]where      stuaddress=@addressgo--掉用存储过程:exec proc_GetStuInfo '沙坪坝'/*学号    姓名    年龄    性别    电话    地址---------------------------------------------------1    张三    20    男    13456780990    沙坪坝2    李四    20    男    13456780990    沙坪坝4    美女    19    女    13256357854    沙坪坝*/ 

热点排行