小白,求解不知道哪错了

丶云淡风轻丶 2013-05-05 03:07:41
USE [BankMan]
GO
/****** Object: StoredProcedure [dbo].[_PageQuerys1] Script Date: 05/05/2013 14:09:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[_PageQuerys1]
@PageIndex int, --当前第几页
@PageSize int, --每页行数
@Name nvarchar(31), --用户
@Number nvarchar(31),--银行卡号
@AccountType int, --卡类别 1、个人 2、企业
@BankName nvarchar(63), --银行名称
@OrderValue varchar(100) --排序字段
as
declare
@StrSql varchar(3000), --主查询语句
@WhereSql varchar(3000)
begin
if @Name is not null or @Name<>''
begin
set @WhereSql=N' and a.Name='''+@Name+''''
end
if @Number is not null or @Number<>''
begin
set @WhereSql=@WhereSql+N' and a.Number='''+@Number+''''
end
print @AccountType
if @AccountType<>0
begin
set @WhereSql=@WhereSql+' and a.AccountType='+@AccountType
end
if @BankName is not null or @BankName <>''
begin
set @WhereSql=@WhereSql+N' and b.BankName='''+@BankName+''''
end
if @WhereSql is null or @WhereSql=''
begin
set @WhereSql=''
end
set @StrSql=N'select abc.* from
(select ROW_NUMBER() over (order by ab.[AccountId] desc ) as rowid,ab.* from
(select a.[AccountId], b.BankName,b.Logo,a.[Name],a.[Number],a.[LastUpdateTime],
a.[MaximumLimit],a.[Current],a.[Detail],a.[CreateTime],
(case a.[Type] when 1 then ''个人'' else ''企业'' end) as AccountType ,
a.Level,(case a.[State] when 1 then ''生效'' when 2 then ''冻结'' else ''注销'' end) as AccountState
from BankAccounts as a,Banks as b
where a.[BankID]=b.[BankID] '+@WhereSql+')ab)abc
where abc.rowid>'+convert(nvarchar(50),(@PageIndex - 1) * @PageSize)+'
and abc.rowid<='+convert(nvarchar(50),(@PageIndex * @PageSize))+' '
--if @OrderValue is not null or @OrderValue <>''
-- begin
-- set @StrSql=@StrSql+' order by '+@OrderValue
-- end
--else
-- begin
-- set @StrSql=@StrSql+N' order by abc.LastUpdateTime'
-- end
exec (@StrSql)
print @StrSql
end


...全文
140 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
丶云淡风轻丶 2013-05-06
  • 打赏
  • 举报
回复
if @Name is not null and len(@Name)>0 新 if @Name is not null or @Name<>'' 旧 判断的问题,参数等于'',旧的无法进行判断
daiyueqiang2045 2013-05-06
  • 打赏
  • 举报
回复
当你的那个参数为""是,你看一下print 出来的sql语句是你预期的sql吗?
發糞塗牆 2013-05-06
  • 打赏
  • 举报
回复
那你先找到你那个“”是哪个参数,然后到你代码中看这个参数对空字符串的处理是否不合理。
丶云淡风轻丶 2013-05-06
  • 打赏
  • 举报
回复
引用 3 楼 DBA_Huangzj 的回复:
你那个exec先去掉,先print出来看看能不能执行。另外你那个不能执行是指报错还是没数据?
数据库执行的时候是对的 ,程序调用时传""值就显示查不到 ,但是有值就可以
發糞塗牆 2013-05-06
  • 打赏
  • 举报
回复
你那个exec先去掉,先print出来看看能不能执行。另外你那个不能执行是指报错还是没数据?
丶云淡风轻丶 2013-05-05
  • 打赏
  • 举报
回复
丶云淡风轻丶 2013-05-05
  • 打赏
  • 举报
回复

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧