create table #table1 (姓名 varchar(100), 岗位 varchar(100), 试用系数 varchar(100), 基本月薪 varchar(100), 基本绩效奖金 varchar(100)) insert into #table1 values ('张三','文员','1.0','1500','1500') insert into #table1 values ('李四','负责人','1.0','2500','2500') insert into #table1 values ('李五','负责大人','1.0','3500','3500') select * from ( select t2.*,t1.姓名 as 姓名1 from #table1 t1, (select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
union select t1.*, t1.姓名 as 姓名1 from #table1 t1, (select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2 ) tt order by 姓名1, 试用系数 desc drop table #table1
to 我爱机器猫 这样的话,我现在单位有1000来人,岂不是要insert1000来次? 这里的数据能不能够从原来的表里面读出来,比如从 select * into #table from tableA if .... then.... else...
这样的话,我现在单位有1000来人,岂不是要insert1000来次? --- 你把机器貌的#table1改成你的表名就可以了。 如下在查询分析器中执行:select * from ( select t2.*,t1.姓名 as 姓名1 from 你的表名 t1, (select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
union select t1.*, t1.姓名 as 姓名1 from 你的表名 t1, (select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2 ) tt order by 姓名1, 试用系数 desc
看我的,绝对可以运行: select 姓名,岗位,试用系数,基本月薪,基本绩效奖金 from ( select 姓名 ID1 ,姓名,岗位,试用系数,基本月薪,基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName ) a
由于类型的原因,可能要再改进一下:select 姓名,岗位,试用系数,基本月薪,基本绩效奖金 from ( select 姓名 ID1 ,姓名,岗位,cast(试用系数 as varchar) 试用系数,cast(基本月薪 as varchar) 基本月薪,cast(基本绩效奖金 as varchar) 基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName ) a
/* 功能:实现打印工资条 注意:原来的表中的类型的转换,如果是数字的需要转换为varchar */-- 建立测试表 create table #t ( 姓名 varchar(10), 岗位 varchar(10), 试用系数 decimal(10,2), 基本月薪 int, 基本绩效奖金 int ) -- 插入测试数据 insert into #t values ('张三','文员',1.0,1500,1500) insert into #t values ('李四','负责人',1.0,2500,2500) insert into #t values ('王五','经理',1.0,3500,3500) insert into #t values ('刘六','秘书',1.0,5000,5000)-- 查看原表 select * from #t-- 打印工资条(查询结果) select 姓名,岗位,试用系数,基本月薪,基本绩效奖金 from ( select 姓名 姓名1,姓名,岗位,cast(试用系数 as varchar) 试用系数,cast(基本月薪 as varchar) 基本月薪,cast(基本绩效奖金 as varchar) 基本绩效奖金 from #t union select 姓名 姓名2,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数,'基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from #t ) a order by 姓名1,试用系数 desc--删除测试表 drop table #t/* 结果如下: 姓名 岗位 试用系数 基本月薪 基本绩效奖金 ---------- ---------- ------------ ----------- ----------- 张三 文员 1.00 1500 1500 李四 负责人 1.00 2500 2500 王五 经理 1.00 3500 3500 刘六 秘书 1.00 5000 5000(所影响的行数为 4 行)姓名 岗位 试用系数 基本月薪 基本绩效奖金 ---------- ---------- ------------------------------ 姓名 岗位 试用系数 基本月薪 基本绩效奖金 李四 负责人 1.00 2500 2500 姓名 岗位 试用系数 基本月薪 基本绩效奖金 刘六 秘书 1.00 5000 5000 姓名 岗位 试用系数 基本月薪 基本绩效奖金 王五 经理 1.00 3500 3500 姓名 岗位 试用系数 基本月薪 基本绩效奖金 张三 文员 1.00 1500 1500 */
Server: Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to float.老是如此提示: 这个里面有很多金额是float类型的,是不是要将所有的float类型cast成varchar? 另外一个问题: excel怎么样才能够将数据导进去的时候不变成float类型
这个里面有很多金额是float类型的,是不是要将所有的float类型cast成varchar? --- 这个是要转换的,不然产生的是一个字段将会有两个种类型,一个是float,另外一个是varchar,产生冲突,就出错了。 如下: select 1 a -- 将产生一个列名为a,类型是int,因为1默认是数字。 union select 'a' a -- 将产生一个列名为a,类型是varchar,因为'a'是字符。 所以联合查询的时候将发生类型冲突。修改成为如下就可以了: select cast(1 as varchar) a union select 'a' a--- 所以你可以将你的类型转为varchar就可以了。 其实打印工资条在sql里面实现不如通过其他的方法实现的方便,前台程序很容易处理的。
宏这个东西我倒是没有用过,能否教我一招!
FoxPro会不会,简单做一下就可以了
岗位 varchar(100),
试用系数 varchar(100),
基本月薪 varchar(100),
基本绩效奖金 varchar(100))
insert into #table1 values ('张三','文员','1.0','1500','1500')
insert into #table1 values ('李四','负责人','1.0','2500','2500')
insert into #table1 values ('李五','负责大人','1.0','3500','3500') select * from (
select t2.*,t1.姓名 as 姓名1 from #table1 t1,
(select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
union
select t1.*,
t1.姓名 as 姓名1 from #table1 t1,
(select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
) tt order by 姓名1, 试用系数 desc
drop table #table1
这样的话,我现在单位有1000来人,岂不是要insert1000来次?
这里的数据能不能够从原来的表里面读出来,比如从
select * into #table from tableA
if ....
then....
else...
---
你把机器貌的#table1改成你的表名就可以了。
如下在查询分析器中执行:select * from (
select t2.*,t1.姓名 as 姓名1 from 你的表名 t1,
(select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
union
select t1.*,
t1.姓名 as 姓名1 from 你的表名 t1,
(select '姓名' as 姓名 ,'岗位' as 岗位,'试用系数' as 试用系数,'基本月薪' as 基本月薪,'基本绩效奖金' as 基本绩效奖金) t2
) tt order by 姓名1, 试用系数 desc
在excel中,工具-宏-录制新宏
按你的需要,记录下来,再稍做修改,就行了。
select 姓名,岗位,试用系数,基本月薪,基本绩效奖金
from (
select 姓名 ID1 ,姓名,岗位,试用系数,基本月薪,基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName
) a
from (
select 姓名 ID1 ,姓名,岗位,cast(试用系数 as varchar) 试用系数,cast(基本月薪 as varchar) 基本月薪,cast(基本绩效奖金 as varchar) 基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName
) a
功能:实现打印工资条
注意:原来的表中的类型的转换,如果是数字的需要转换为varchar
*/-- 建立测试表
create table #t
(
姓名 varchar(10),
岗位 varchar(10),
试用系数 decimal(10,2),
基本月薪 int,
基本绩效奖金 int
)
-- 插入测试数据
insert into #t values ('张三','文员',1.0,1500,1500)
insert into #t values ('李四','负责人',1.0,2500,2500)
insert into #t values ('王五','经理',1.0,3500,3500)
insert into #t values ('刘六','秘书',1.0,5000,5000)-- 查看原表
select * from #t-- 打印工资条(查询结果)
select 姓名,岗位,试用系数,基本月薪,基本绩效奖金 from
(
select 姓名 姓名1,姓名,岗位,cast(试用系数 as varchar) 试用系数,cast(基本月薪 as varchar) 基本月薪,cast(基本绩效奖金 as varchar) 基本绩效奖金 from #t
union
select 姓名 姓名2,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数,'基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from #t
) a order by 姓名1,试用系数 desc--删除测试表
drop table #t/*
结果如下:
姓名 岗位 试用系数 基本月薪 基本绩效奖金
---------- ---------- ------------ ----------- -----------
张三 文员 1.00 1500 1500
李四 负责人 1.00 2500 2500
王五 经理 1.00 3500 3500
刘六 秘书 1.00 5000 5000(所影响的行数为 4 行)姓名 岗位 试用系数 基本月薪 基本绩效奖金
---------- ---------- ------------------------------
姓名 岗位 试用系数 基本月薪 基本绩效奖金
李四 负责人 1.00 2500 2500
姓名 岗位 试用系数 基本月薪 基本绩效奖金
刘六 秘书 1.00 5000 5000
姓名 岗位 试用系数 基本月薪 基本绩效奖金
王五 经理 1.00 3500 3500
姓名 岗位 试用系数 基本月薪 基本绩效奖金
张三 文员 1.00 1500 1500
*/
Error converting data type varchar to float.老是如此提示:
这个里面有很多金额是float类型的,是不是要将所有的float类型cast成varchar?
另外一个问题:
excel怎么样才能够将数据导进去的时候不变成float类型
---
这个是要转换的,不然产生的是一个字段将会有两个种类型,一个是float,另外一个是varchar,产生冲突,就出错了。
如下:
select 1 a -- 将产生一个列名为a,类型是int,因为1默认是数字。
union
select 'a' a -- 将产生一个列名为a,类型是varchar,因为'a'是字符。
所以联合查询的时候将发生类型冲突。修改成为如下就可以了:
select cast(1 as varchar) a
union
select 'a' a---
所以你可以将你的类型转为varchar就可以了。
其实打印工资条在sql里面实现不如通过其他的方法实现的方便,前台程序很容易处理的。