仅显示最近的日期 [英] Show-Only-Most-Recent-Date-Fro...

查看:104
本文介绍了仅显示最近的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmd.CommandText =选择facno,max(fdate)作为fdate,从MAINTRAN wheere fdate< ="''&Format(prdate,"yyyy/MM/dd")&''GROUP BY facno"

cmd.CommandText = "select facno,max(fdate) as fdate,fbalance from MAINTRAN wheere fdate<=''" & Format(prdate, "yyyy/MM/dd") & "'' GROUP BY facno "

推荐答案

这里有两件事:Tomas Takac在上面的评论中提到了平衡问题,"wheere"的拼写以及连接的使用.

不要连接字符串以构建SQL命令.它使您对意外或蓄意的SQL注入攻击敞开大门,这可能会破坏整个数据库.请改用参数化查询.这是一种安全的用法,但是如果您在此处进行操作,则很可能在其他地方进行操作,并使数据库容易受到攻击.
试试这个:
There are a couple of things here: there is the fbalance problem mentioned by Tomas Takac in the comments above, the spelling of "wheere", and the use of concatenation.

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. This is a safe use, but if you are doing it here, the chances are you do it elsewhere and leave your database wide open to attack.
Try this:
cmd.CommandText = "SELECT facno, MAX(fdate) AS fdate, SUM(fbalance) AS totalfbalance FROM MainTran WHERE fdate<=@DT GROUP BY facno"
cmd.Parameters.AddWithValue("@DT", prdate.Date)


感谢它的工作...闭幕式:这里是我的工作查询:----

thanks its works ...closing cermany:here my working query:----

"select facno,max(fdate) as fdate ,max(fbalance) as fbalance from MAINTRAN where MAINTRAN.fbankcode='" & "010" & "'" & _
                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                          "and MAINTRAN.fbranchcode='" & "01" & "' group by facno"



感谢上帝,它的作品.....



thank god its works.....


这篇关于仅显示最近的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆