sql过程中的错误 [英] error in sql procedure

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

问题描述





i想知道我该如何解决这个错误



Hi

i would like to know how can i solve this error

Error converting data type nvarchar to datetime


当我运行此程序时





when i run this procedure

alter proc Ledger

@Account_Serial int ,
@DateFrom datetime,
@DateTo datetime
as


SELECT     GLD_JOURNAL_ENTRY_DETAILES.ACCOUNT_SERILA_NO, SUM(GLD_JOURNAL_ENTRY_DETAILES.DEBIT_VALUE) AS DEBIT_VALUE, 
                      SUM(GLD_JOURNAL_ENTRY_DETAILES.CREDIT_VALUE) AS CREDIT_VALUE
FROM         GLD_JOURNAL_ENTRY_DETAILES INNER JOIN
                      GLD_JOURNAL_ENTRIES ON GLD_JOURNAL_ENTRY_DETAILES.JOURNAL_ENTRY_NO = GLD_JOURNAL_ENTRIES.Journal_ENTRY_NO
WHERE     (GLD_JOURNAL_ENTRIES.TRANSFER_DATE --BETWEEN @DateFrom AND @DateTo
between convert(datetime ,CONVERT(nvarchar(20),@DateFrom) ,102)
 and convert(datetime,CONVERT(nvarchar(20),@DateTo) ,105)
)

 
 
GROUP BY GLD_JOURNAL_ENTRY_DETAILES.ACCOUNT_SERILA_NO
HAVING      (GLD_JOURNAL_ENTRY_DETAILES.ACCOUNT_SERILA_NO = @Account_Serial)





任何想法



any idea

推荐答案

为什么要传递DateTime值(明智),然后将它们转换为Sql默认格式(yyyy-MM-dd),然后尝试将它们转换回日期时间,就好像它们一样是ANSI格式(yy.MM.dd)?

只需在评论中直接使用它们,或使用CAST删除时间部分:

Why are you passing DateTime values (sensible) and then converting them to the Sql default format (yyyy-MM-dd) and then trying to convert them back to a datetime as if they were in ANSI format (yy.MM.dd)?
Just use them directly as in your comments, or use CAST to remove the time portion:
WHERE GLD_JOURNAL_ENTRIES.TRANSFER_DATE BETWEEN CAST(@DateFrom AS DATE) AND CAST(@DateTo AS DATE)


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

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