以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教自动编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=42754)

--  作者:seintfei
--  发布时间:2013/11/21 9:59:00
--  请教自动编号

请教各位自己编号问题,情况如下:

 

内部报价编号:IPHYK31101A1-1   

 

IP(固定值)+项目编号(想通过上一列读取)+数字(代表第几次报价,更新一次报价自动递增)

 

以上应该怎么做才能实现?


--  作者:Bin
--  发布时间:2013/11/21 10:11:00
--  
参考一下这里 http://www.foxtable.com/help/topics/2403.htm
--  作者:seintfei
--  发布时间:2013/11/21 12:06:00
--  
没做成功...能不能改个实例给我~谢谢!
--  作者:Bin
--  发布时间:2013/11/21 12:13:00
--  
你要先上例子,带上数据,说明想实现的效果. 别人才能帮上你忙啊.

你既然看不懂帮助,我写个例子给你,你也不一定会套用,.

--  作者:longtechwj
--  发布时间:2013/11/21 14:16:00
--  
SELECT \'SP\'+SUBSTRING(CAST(YEAR(GETDATE()) AS NVARCHAR(MAX)),3,2)+SUBSTRING(\'00\',1,2-LEN(CAST(MONTH(GETDATE()) AS NVARCHAR(MAX))))+CAST(MONTH(GETDATE()) AS NVARCHAR(MAX))
+SUBSTRING(\'00\',1,2-LEN(CAST(DAY(GETDATE()) AS NVARCHAR(MAX))))+CAST(DAY(GETDATE()) AS NVARCHAR(MAX))
+substring(\'000\',1,3-len(cast(cast(substring(MAX(REF_NO),9,3) AS INT)+1 AS NVARCHAR(MAX))))+cast(cast(substring(MAX(REF_NO),9,3) AS INT)+1 AS NVARCHAR(MAX)) FROM Order_Rech 
WHERE LEFT(ref_no,2)=\'SP\'

--  作者:seintfei
--  发布时间:2013/11/21 14:31:00
--  

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("日期"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End
If
End
If

 

 

 

以上代码如果日期取最好一位值,请问怎么改?

 

 

 

 

Select e.DataCol.Name
    Case
"类别"
       
If e.DataRow.IsNull("类别") Then
            e.
DataRow("编号") = Nothing
        Else
            Dim
lb As String = e.DataRow("类别")
            If
e.DataRow("编号").StartsWith(lb) = False \'如果单据编号前缀不符
               
Dim max As String
               
Dim idx As Integer

                max = e.DataTable.Compute("Max(编号)","类别 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
               
If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(
2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
               
Else
                    idx =
1 \'否则顺序号等于1
               
End If
                e.
DataRow("编号") = lb & Format(idx,"000")
            End
If
        End
If
End
Select

 

 

以上代码类别超过2个字符就会报警,请问如何设置可以输入3~4位?


--  作者:狐狸爸爸
--  发布时间:2013/11/21 14:34:00
--  

如果类别的长度不固定:

 

 

Select e.DataCol.Name
    Case "类别"
        If e.DataRow.IsNull("类别") Then
            e.DataRow("编号") = Nothing
        Else
            Dim lb As String = e.DataRow("类别")
            If e.DataRow("编号").StartsWith(lb) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(编号)","类别 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = right(max,3) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("编号") = lb & Format(idx,"000")
            End If
        End If
End Select


--  作者:seintfei
--  发布时间:2013/11/21 14:39:00
--  
非常感谢老师们的帮助
--  作者:seintfei
--  发布时间:2013/11/21 17:30:00
--  

再请教:

 

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("日期"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End
If

End
If

 

 

以上代码生成的日期是年取4位值,现在想实现年取值1位 20131121---》31121 请问怎么改?


--  作者:Bin
--  发布时间:2013/11/21 17:32:00
--  
substring一下 
"20131121".substring(3,5)