工资表与交税等级

来源:互联网 发布:怎么消除激活windows 编辑:程序博客网 时间:2024/04/29 03:10

--用户工资表,交税等级表,工资决定交税等级,现取指定等级的用户名。

--创建测试数据create   table   emp(empid int IDENTITY(1,1) PRIMARY KEY,empname   varchar(10),empsal  int) insert   into   emp   select   'A', '3231'insert   into   emp   select   'B', '1966' insert   into   emp   select   'C', '5564'insert   into   emp   select   'D', '3544'insert   into   emp   select   'E', '5123' go

--select * from emp

create   table   taxinfo(id int identity(1,1) primary key,minsalval int,maxsalval int,taxlevel varchar(4)) insert   into   taxinfo   select   '0', '2000','一'insert   into   taxinfo   select   '2001', '3000','二' insert   into   taxinfo   select   '3001', '4000','三'insert   into   taxinfo   select   '4001', '5000','四'insert   into   taxinfo   select   '5001', '10000','五' go

--select * from taxinfo

--创建函数获取交税等级create function f_getLvl(@val int)returns varchar(1000)asbegin declare @lvl varchar(1000)set @lvl=''select @lvl = taxlevel from taxinfo where maxsalval>=@val  and minsalval<=@valreturn @lvlendgo

--使用临时表,选出交税等级为一的员工的名字create table #tmp (tmpid int,tmpname varchar(10),tmplvl varchar(4))insert into #tmp select empid,empname,dbo.f_getLvl(empsal) from empselect * from #tmp where tmplvl='一'

--删除测试数据--drop table #tmp--drop function f_getLvl--drop table emp--drop table taxinfo

原创粉丝点击