将 nvarchar 值 转换为数据类型为 int 的列时发生语法错误。
这是我写的存储过程,出错:服务器: 消息 245,级别 16,状态 1,过程 sptable,行 41
将 nvarchar 值 转换为数据类型为 int 的列时发生语法错误。
不知道错在哪里,请各位帮我查查错在哪里。谢谢!我写的存储过程过程
水平不高,请帮我在做下优化吧,万分感谢!
Create PROCEDURE sptable
@Identifier nvarchar(50),
@return nvarchar(50) OUTPUT
as
declare @strtable as nvarchar(20)
declare @strtable1 as nvarchar(20)
declare @strtable2 as nvarchar(20)
declare @strtable3 as nvarchar(20)
declare @strtable4 as nvarchar(20)
declare @ireturn as int
declare @ireturn1 as int
declare @ireturn2 as int
declare @ireturn3 as int
declare @ireturn4 as int
select @ireturn=count(*) from dbo.SdaRenewNotify where 申请编号=@Identifier
select @ireturn1=count(*) from dbo.SdaAcceptNotify where 申请编号=@Identifier
select @ireturn2=count(*) from dbo.SdaNotgrantNotify where 编号=@Identifier
select @ireturn3=count(*) from dbo.SdaLocaleNotify where 申请编号=@Identifier
select @ireturn4=count(*) from dbo.SdaSampleNotify where 申请编号=@Identifier
if @iReturn=1
select @strtable = '补正'
if @ireturn1=1
select @strtable1 = '受理'
if @ireturn2=1
select @strtable2 = '不予'
if @ireturn3=1
select @strtable3 = '核查'
if @ireturn4=1
select @strtable4 = '检验'
ProcReturn:
select @return=rtrim(cast(isnull(@strtable,'') as nvarchar(20)))+ rtrim(cast(isnull(@strtable1,'') as nvarchar(20)))+ rtrim(cast(isnull(@strtable2,'') as nvarchar(20)))+ rtrim(cast(isnull(@strtable3,'') as nvarchar(20)))+rtrim(cast(isnull(@strtable4,'') as nvarchar(20)))
--if @@error<>0 goto E_Compile_Fail
return cast(@return as nvarchar(20))
E_Compile_Fail:
declare @lerror int
select @lerror = @@error
RAISERROR (@lerror,17,127)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
问题点数:100、回复次数:5Top
1 楼rea1gz(冒牌realgz V0.4)回复于 2006-12-01 16:47:17 得分 0
去掉
return cast(@return as nvarchar(20))
一句
Top
2 楼rea1gz(冒牌realgz V0.4)回复于 2006-12-01 16:47:54 得分 0
1楼不对
改
return cast(@return as nvarchar(20))
--〉
return
Top
3 楼playwarcraft(时间就像乳沟,挤挤还是有的)回复于 2006-12-01 16:48:50 得分 0
欄位: 申请编号 是什麼類型???Top
4 楼rea1gz(冒牌realgz V0.4)回复于 2006-12-01 16:50:06 得分 100
完整
Create PROCEDURE sptable
@Identifier nvarchar(50),
@return nvarchar(50) OUTPUT
as
declare @strtable as nvarchar(20)
declare @strtable1 as nvarchar(20)
declare @strtable2 as nvarchar(20)
declare @strtable3 as nvarchar(20)
declare @strtable4 as nvarchar(20)
declare @ireturn as int
declare @ireturn1 as int
declare @ireturn2 as int
declare @ireturn3 as int
declare @ireturn4 as int
select @ireturn=count(*) from dbo.SdaRenewNotify where 申请编号=@Identifier
select @ireturn1=count(*) from dbo.SdaAcceptNotify where 申请编号=@Identifier
select @ireturn2=count(*) from dbo.SdaNotgrantNotify where 编号=@Identifier
select @ireturn3=count(*) from dbo.SdaLocaleNotify where 申请编号=@Identifier
select @ireturn4=count(*) from dbo.SdaSampleNotify where 申请编号=@Identifier
if @iReturn=1
select @strtable = N'补正'
if @ireturn1=1
select @strtable1 = N'受理'
if @ireturn2=1
select @strtable2 = N'不予'
if @ireturn3=1
select @strtable3 = N'核查'
if @ireturn4=1
select @strtable4 = N'检验'
ProcReturn:
select @return=isnull(@strtable,'')+ isnull(@strtable1,'')+ isnull(@strtable2,'')+ isnull(@strtable3,'')+ isnull(@strtable4,'')
GO
Top
5 楼ceileng888()回复于 2006-12-01 16:50:56 得分 0
都是强人啊!给分!Top





