用vb或crystal report做个报表很容易解决

解决方案 »

  1.   

    如果你是用execl处理的,不用导到SQL里来,录制一段粘贴标题的宏不就行了。我每个月就是这样处理工资条的,只要几秒钟。
      

  2.   

    to :victorycyz
    宏这个东西我倒是没有用过,能否教我一招!
      

  3.   

    用任何一种数据库开发程序的报表打印均能很方便地实现你所需要的功能。
    FoxPro会不会,简单做一下就可以了
      

  4.   

    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
      

  5.   

    to 我爱机器猫
    这样的话,我现在单位有1000来人,岂不是要insert1000来次?
    这里的数据能不能够从原来的表里面读出来,比如从
    select * into #table from tableA 
    if ....
    then....
    else...
      

  6.   

    这样的话,我现在单位有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
      

  7.   

    我来教你一个简单的方法:
    在excel中,工具-宏-录制新宏
    按你的需要,记录下来,再稍做修改,就行了。
      

  8.   

    看我的,绝对可以运行:
    select 姓名,岗位,试用系数,基本月薪,基本绩效奖金
    from (
    select 姓名 ID1 ,姓名,岗位,试用系数,基本月薪,基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName
    ) a
      

  9.   

    由于类型的原因,可能要再改进一下:select 姓名,岗位,试用系数,基本月薪,基本绩效奖金
    from (
    select 姓名 ID1 ,姓名,岗位,cast(试用系数 as varchar) 试用系数,cast(基本月薪 as varchar) 基本月薪,cast(基本绩效奖金 as varchar) 基本绩效奖金 from TableName group by 姓名,岗位,试用系数,基本月薪,基本绩效奖金 union select 姓名 ID1 ,'姓名' 姓名,'岗位' 岗位,'试用系数' 试用系数, '基本月薪' 基本月薪,'基本绩效奖金' 基本绩效奖金 from TableName
    ) a
      

  10.   

    /*
    功能:实现打印工资条
    注意:原来的表中的类型的转换,如果是数字的需要转换为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
    */
      

  11.   

    Server: Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to float.老是如此提示:
    这个里面有很多金额是float类型的,是不是要将所有的float类型cast成varchar?
    另外一个问题:
    excel怎么样才能够将数据导进去的时候不变成float类型
      

  12.   

    在excel中将单元格类型设置成,文本型的
      

  13.   

    Sub 生成工资条()Cells.Select'选择整个表去掉表格线Range("F1").ActivateSelection.Borders(xlDiagonalDown).LineStyle = xlNoneSelection.Borders(xlDiagonalUp).LineStyle = xlNoneSelection.Borders(xlEdgeLeft).LineStyle = xlNoneSelection.Borders(xlEdgeTop).LineStyle = xlNoneSelection.Borders(xlEdgeBottom).LineStyle = xlNoneSelection.Borders(xlEdgeRight).LineStyle = xlNoneSelection.Borders(xlInsideVertical).LineStyle = xlNoneSelection.Borders(xlInsideHorizontal).LineStyle = xlNoneRows("2:2").Select'选择第2行Selection.Insert Shift:=xlDown'在第2行前插入一行,保持第2行为选中状态num = 2310'总人数×3,如工资表中有100人则为100×3即num = 300col = 27'工资表的栏数,如工资表有17栏则'col=17num1 = 4Do While num1 <= num'循环插入空行Range(Cells(num1, 1), Cells(num1, col)).Select'选中第num1行的第1列到第col列Selection.Insert Shift:=xlDownSelection.Insert Shift:=xlDownnum1 = num1 + 3LoopRange(Cells(1, 1), Cells(1, col)).SelectApplication.CutCopyMode = False'剪切复制模式无效Selection.Copy'复制选择区域Range("A2").Select'选择A2单元格ActiveSheet.Paste'从A2单元格起粘贴内容num2 = 5Do While num2 <= num'循环插入标题行Range(Cells(1, 1), Cells(1, col)).SelectApplication.CutCopyMode = FalseSelection.CopyCells(num2, 1).SelectActiveSheet.Pastenum2 = num2 + 3LoopRange(Cells(2, 1), Cells(3, col)).SelectApplication.CutCopyMode = FalseSelection.Borders(xlDiagonalDown).LineStyle = xlNone'定义表格边框线、内线样式Selection.Borders(xlDiagonalUp).LineStyle = xlNoneWith Selection.Borders(xlEdgeLeft).LineStyle = xlDouble.Weight = xlThick.ColorIndex = xlAutomaticEnd WithWith Selection.Borders(xlEdgeTop).LineStyle = xlDouble.Weight = xlThick.ColorIndex = xlAutomaticEnd WithWith Selection.Borders(xlEdgeBottom).LineStyle = xlDouble.Weight = xlThick.ColorIndex = xlAutomaticEnd WithWith Selection.Borders(xlEdgeRight).LineStyle = xlDouble.Weight = xlThick.ColorIndex = xlAutomaticEnd WithWith Selection.Borders(xlInsideVertical).LineStyle = xlDash.Weight = xlThin.ColorIndex = xlAutomaticEnd WithWith Selection.Borders(xlInsideHorizontal).LineStyle = xlDash.Weight = xlThin.ColorIndex = xlAutomaticEnd WithSelection.CopyRange(Cells(5, 1), Cells(6, col)).SelectSelection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False'接上行删除上行尾的连字符_,复制表格线样式num3 = 8Do While num3 <= num'循环复制表格线样式Range(Cells(num3, 1), Cells(num3 + 1, col)).SelectSelection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=Falsenum3 = num3 + 3LoopRows("1:1").Select'删除多余的一行Selection.DeleteEnd Sub
      

  14.   

    这个里面有很多金额是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里面实现不如通过其他的方法实现的方便,前台程序很容易处理的。