sql代码 怎么简化呢?
当前代码如下:
Public Sub form593_upd ate2_Ajax(rq as Request)
Dim e As RequestEventArgs = rq.e
Dim cmd As SQ LCo mmand = rq.cmd
cmd.Com mandText = "sele ct sum(价值或金额) from " & e.Values("表名") & " where 主表guid='" & e.Values("guid") & "' and 财物类型='款项' and 登记状态='" & e.Values("登记状态") & "'"
If cmd.ExecuteScalar > 0 Then
cmd.Comm andText = "upd ate " & e.Values("更新表名") & " set 本次款项总计 = " & cmd.ExecuteScalar & " where 主表guid='" & e.Values("guid") & "'"
cmd.ExecuteReader()
End If
cmd.Comm andText = "sel ect sum(数量) from " & e.Values("表名") & " where 主表guid='" & e.Values("guid") & "' and 财物类型<>'款项' and 登记状态='" & e.Values("登记状态") & "'"
If cmd.ExecuteScalar > 0 Then
cmd.Comm andText = "upd ate " & e.Values("更新表名") & " set 本次物品总计 = " & cmd.ExecuteScalar & " where 主表guid='" & e.Values("guid") & "'"
cmd.ExecuteReader()
End If
cmd.Comman dText = "sel ect sum(本次款项总计) from " & e.Values("更新表名") & " where 主表guid='" & e.Values("guid") & "'"
If cmd.ExecuteScalar > 0 Then
cmd.Comm andText = "upd ate " & e.Values("更新表名") & " set 历史款项总计 = " & cmd.ExecuteScalar & " where 主表guid='" & e.Values("guid") & "'"
cmd.ExecuteReader()
End If
cmd.Comma ndText = "sel ect sum(本次物品总计) from " & e.Values("更新表名") & " where 主表guid='" & e.Values("guid") & "'"
If cmd.ExecuteScalar > 0 Then
cmd.Com mandText = "upd ate " & e.Values("更新表名") & " set 历史物品总计 = " & cmd.ExecuteScalar & " where 主表guid='" & e.Values("guid") & "'"
cmd.ExecuteReader()
End If
e.WriteString("")
End Sub