【问题标题】:SQL Server stored procedure coming up emptySQL Server 存储过程为空
【发布时间】:2012-06-16 18:18:22
【问题描述】:

我有一个 SQL Server 存储过程,当我插入参数时它不返回任何数据...

ALTER PROCEDURE dbo.EncumBugSearch 
@year datetime
AS
BEGIN

SET NOCOUNT ON;

    select *
From dbo.BudgetEncumberedTbl as bet
where year(dateadd(month,-3,bet.be_dateposted)) = @year
order by be_dateposted desc

END
GO

但是,当我为参数插入一个数字(即 2011 年)时,这不会返回任何内容,然后我会得到正确的结果......有什么想法吗?

【问题讨论】:

  • 您说的是 SQL(结构化查询语言 - 一种独立于供应商的语言),但您真正的意思是 SQL Server(微软的关系数据库产品)- 对?
  • 如何将参数传递给存储过程?
  • 是的 SQL Server(我很抱歉),我通过我的 asp.net 页面上的用户选择的项目传递它。
  • @year 作为日期时间的格式与 where 子句中的年份不同....换句话说 1/1/2012 year(dateadd(month-3)bet .be_Dateposted) 可能是 2012 年。所以 2012 年 1 月 1 日 2012 年。你不需要年份(@year)吗?

标签: sql-server stored-procedures data-retrieval


【解决方案1】:

你的参数是一个日期时间,当it should be an int

【讨论】:

    猜你喜欢
    • 2014-12-08
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多