Foxtable(狐表)用户栏目专家坐堂 → [求助]日期统计问题


  共有2874人关注过本帖树形打印复制链接

主题:[求助]日期统计问题

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 9:13:00 [显示全部帖子]

 也没看懂。

 

 第一级是姓名,第二级是年,第三级是月,第四级是日?


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 10:08:00 [显示全部帖子]

 。。。。。。代码

 

Dim cmd As new SQLCommand
cmd.CommandText = "Select 开piao人信息_姓名 As 姓名,开piao日期1_日期 As 日期, year(开piao日期1_日期) As 年, month(开piao日期1_日期) As 月, day(开piao日期1_日期) As 日, 1 as 开单 from {信息录入表} where 开piao人信息_姓名 Is not null " _
& " union Select 开piao人信息_姓名,开piao日期2_日期, year(开piao日期2_日期), month(开piao日期2_日期) As 月, day(开piao日期2_日期), 1 from {信息录入表} where 开piao人信息_姓名 Is not null" _
& " union Select 开piao人信息_姓名,开piao日期3_日期, year(开piao日期3_日期), month(开piao日期3_日期) As 月, day(开piao日期3_日期), 1 from {信息录入表} where 开piao人信息_姓名 Is not null"
Dim dt As DataTable = cmd.ExecuteReader

For Each ary As String() In dt.GetValues("姓名|年")
    For i As Integer = 1 To 12
        For j As Integer = 1 To Date.DaysInMonth(ary(1),i)
            Dim d As Date = new Date(ary(1), i, j)
            Dim fdr As DataRow = dt.Find("姓名 = '" & ary(0) & "' and 日期 = #" & d & "#")
            If fdr Is Nothing Then
                fdr = dt.AddNew
                fdr("姓名") = ary(0)
                fdr("日期") = d
                fdr("年") = ary(1)
                fdr("月") = i
                fdr("日") = j
                fdr("开单") = 0
            End If
        Next
    Next
Next

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
tv.BuildTree(dt, "姓名|年|月|日")
For Each nd As WinForm.TreeNode In tv.AllNodes
    Select Case nd.Level
        Case 0
            nd.Text = nd.Text & "(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1") & "张)"
        Case 1
            nd.Text = nd.Text & "年(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "'") & "张)"
        Case 2
            nd.Text = nd.Text & "月(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "'") & "张)"
        Case 3
            nd.Text = nd.DataRow("月") & "月" & nd.Text & "日(" & dt.Compute("count(姓名)", "姓名 = '" & nd.DataRow("姓名") & "' and 开单 = 1 and 年 = '" & nd.DataRow("年") & "' and 月 = '" & nd.DataRow("月") & "' and 日 = '" & nd.DataRow("日") & "'") & "张)"
    End Select
Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 11:51:00 [显示全部帖子]

你看看是不是name和date的问题,改成别的名字,比如 名字、日期 或者 tname、tdate

 

----------------------------

 

1、你加入代码output.show(cmd.CommandText) 然后在命令窗口看一下得出的sql语句是什么;

 

2、拷贝得出的sql语句,测试一下,看报什么错 http://www.foxtable.com/help/topics/1484.htm

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 11:58:00 [显示全部帖子]

 把 As Date 改成 As 日期

 

 下面对应的也改一下


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/8/15 14:15:00 [显示全部帖子]

 你这一句改一下

 

For Each ary As String() In dt.GetValues("姓名|年", "年 is not null")


 回到顶部