SQL存储过程(含变量)like语句实现不了
USE[DBXXX]GO/******对象:StoredProcedure[dbo].[Proc_DepartSellForm]脚本日期:12/20/201214:46:...
USE [DBXXX]
GO
/****** 对象: StoredProcedure [dbo].[Proc_DepartSellForm] 脚本日期: 12/20/2012 14:46:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Proc_EVA_DepartSellForm]
-- Add the parameters for the stored procedure here
@Begtime datetime,
@Endtime datetime,
@Depart char
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- SET NOCOUNT ON;
declare @beg datetime
declare @End datetime
declare @dept nvarchar
select @beg=@Begtime
select @End=@Endtime
select @dept=@Depart
select *
from table
where fdate>=@beg and fdate<=@end and fname like '%'+@dept+'%'
END
============================================
执行语句是
set nocount ON
exec Proc_EVA_DepartSellForm '2012-11-1','2012-12-1','北京'
就是要查在beg到end的时间里,部门是北京的单据
结果运行:无结果
去掉 fname like '%'+@dept+'%' 能显示所有部门的单据
如果select @dept=‘北京' 也能实现预想效果
似乎是@Depart变量的问题
求教各位大神是哪写错了 展开
GO
/****** 对象: StoredProcedure [dbo].[Proc_DepartSellForm] 脚本日期: 12/20/2012 14:46:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Proc_EVA_DepartSellForm]
-- Add the parameters for the stored procedure here
@Begtime datetime,
@Endtime datetime,
@Depart char
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- SET NOCOUNT ON;
declare @beg datetime
declare @End datetime
declare @dept nvarchar
select @beg=@Begtime
select @End=@Endtime
select @dept=@Depart
select *
from table
where fdate>=@beg and fdate<=@end and fname like '%'+@dept+'%'
END
============================================
执行语句是
set nocount ON
exec Proc_EVA_DepartSellForm '2012-11-1','2012-12-1','北京'
就是要查在beg到end的时间里,部门是北京的单据
结果运行:无结果
去掉 fname like '%'+@dept+'%' 能显示所有部门的单据
如果select @dept=‘北京' 也能实现预想效果
似乎是@Depart变量的问题
求教各位大神是哪写错了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询