7 个解决方案
#1
最好别这样,那个序号随着时间的转移,由于删除和添加,可能不连续,建议别关联起来。
#2
lz是指vb里?还是sql server里?
#3
sql server里,请哪位老师指点一下
#4
vb 里这样做
Private Function s_fun_GetID() As String
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function
#5
sql server应该怎么写,写在哪里
#6
SQL中可以写在触发器里
#7
Private Function s_fun_GetID() As String
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function
#1
最好别这样,那个序号随着时间的转移,由于删除和添加,可能不连续,建议别关联起来。
#2
lz是指vb里?还是sql server里?
#3
sql server里,请哪位老师指点一下
#4
vb 里这样做
Private Function s_fun_GetID() As String
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function
#5
sql server应该怎么写,写在哪里
#6
SQL中可以写在触发器里
#7
Private Function s_fun_GetID() As String
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function
Dim strID As String
Dim strF As String
Dim resF As New ADODB.Recordset
strID = qianzhui & Trim(Format(Date, "yymmdd"))
strF = ""
strF = strF & " SELECT MAX(MID(MY_ID, 8, 2)) MAX_ID" & vbNewLine
strF = strF & " FROM MY_TABLE " & vbNewLine
strF = strF & " WHERE MID(MY_ID, 1, 7) = '" & strID & "' " & vbNewLine
resF.Open strF, P_Connect
If Val(resF.Fields("MAX_ID") & "") = 0 Then
strID = strID & "01"
Else
strID = strID & Right("00" & (Val(resF.Fields("MAX_ID") & "") + 1), 2)
End If
resF.Close
Set resF = Nothing
s_fun_GetID = strID
End Function