日期部分的sql过程问题 [英] sql procedure problem with DatePart

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

问题描述

我对Microsoft专业人士的尊重.我的问题:我有20个站使用的VB6应用程序,它是基于SQL Server 2000的.当用户仅选择2011时,一个过程返回记录从2010年开始.该过程返回表中的键为日期的数据 field(RepDateTime):smalldatetime类型.要获取开发人员使用的日期范围输入日历并将这些日期转换为DatePart整数,这些整数用作存储过程的参数.存储过程用来获取范围(比较)转换smalldatetime 也可以转换为datepart值:

My respect to microsoft professional. My question: I have VB6 application used by 20 stations, it is SQL server 2000 based. One Procedure return records from 2010 year when user select only 2011. This procedure return data from table where key is date field(RepDateTime): smalldatetime type. To get date range developer used  input calendars and converted these dates into DatePart integers which were used as parameters to store procedure. Store procedure uses in order to get range(compare) converts smalldatetime also into datepart value:

GO
更改步骤[dbo].[qryProductionCapacity]
@workID int,@ fromDate int,@ toDate int
AS
选择dbo.ProdReport.EmpID,dbo.ProdReport.empName,SUM(dbo.ProdReport.ActQuantity),dbo.ProdReport.WorkID,
来自dbo.ProdReport
在哪里(DATEPART(dayofyear,dbo.ProdReport.RepDateTime)+ YEAR(dbo.ProdReport.RepDateTime)@fromDate和@toDate之间)

GO
ALTER PROCEDURE [dbo].[qryProductionCapacity]
@workID int, @fromDate int, @toDate int
AS
SELECT dbo.ProdReport.EmpID, dbo.ProdReport.empName, SUM(dbo.ProdReport.ActQuantity), dbo.ProdReport.WorkID,
FROM dbo.ProdReport
WHERE (DATEPART(dayofyear, dbo.ProdReport.RepDateTime) + YEAR(dbo.ProdReport.RepDateTime) BETWEEN @fromDate AND @toDate)

这个问题是在2011年新的一年开始时发现的.通过以下方式从VB6创建参数:

The problem was discovered with beggining of new 2011 year. From VB6 parameters were created by follow way:

Dim from Date As Long
昏昏欲睡的日期
    fromDate = DatePart("y",Trim(txtFromDate.Text))+ Year(Trim(txtFromDate.Text))
    toDate = DatePart("y",Trim(txtToDate.Text))+ Year(Trim(txtToDate.Text))

Dim fromDate As Long
Dim toDate As Long
    fromDate = DatePart("y", Trim(txtFromDate.Text)) + Year(Trim(txtFromDate.Text))
    toDate = DatePart("y", Trim(txtToDate.Text)) + Year(Trim(txtToDate.Text))

我不知道它的正确但不同的日期是否给出相同的整数值.例如,2011年1月6日-给出了2017年,2010年1月7日也给出了2017年,2009年1月8日也给出了2017年,因此程序最终也返回了2009年和2010年的结果

I do not know if its correct but different dates gives same integers value. For example 6 Jan 2011 - gives 2017, also 7 Jan 2010 gives 2017, also 8 Jan 2009 gives 2017, so finally procedure returns results also from 2009 and 2010

是否可以更改WHERE语句,所以我确实需要更改申请?预先感谢

Is it possible to change WHERE statement so I do need  change application? Thanks in advance

推荐答案

你好,迈克尔,

  跨度>

谢谢您的发帖!  ;我建议您在一个MS论坛中发布您的问题,

Thank you for your post!  I would suggest posting your question in one of the MS Forum,

SQL Server > SQL Server论坛 > SQL Server数据访问
SQL Server > SQL Server Forums > SQL Server Data Access


这篇关于日期部分的sql过程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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