简单问题

FrameSniper 2008-09-24 03:22:50
假设我有个存储过程带着money个参数,一个是bit类型,一个是real类型,还有一个是money类型

我在用execute调用的时候如下写

execute udsp_SomeProc 1,100.98,54.5

(假设存储过程名称为udsp_SomeProc)

这样可以吗,至少bit类型这样写会报错
...全文
110 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinqi025 2008-09-24
  • 打赏
  • 举报
回复
看一下顺序
nalnait 2008-09-24
  • 打赏
  • 举报
回复
兄弟,我测试了,你的没问题啊。把表结构也贴上来
wgzaaa 2008-09-24
  • 打赏
  • 举报
回复
问题好象不在这里,都是smallint型转的,否则会报转smallint错误,是不是还有未贴的?
qinhl99 2008-09-24
  • 打赏
  • 举报
回复
没有错!
动态语句,数值型和bit不要加多余的引号,倒是楼主可能的错误原因
fcuandy 2008-09-24
  • 打赏
  • 举报
回复
try


set @InsertStatement='insert into udsdt_TrainCarriageType (tctf_Index,tctf_Name,tctf_StandardLoadIndex) values ('+ rtrim(@Index)+','''+ @Name + ''', '+ rtrim(@StandardLoadIndex)+')' 
昵称被占用了 2008-09-24
  • 打赏
  • 举报
回复
动态语句,数值型和bit不要加多余的引号
昵称被占用了 2008-09-24
  • 打赏
  • 举报
回复
去掉几个引号试试

create procedure udsp_InsertTrainCarriageType
@Name nvarchar(16),
@StandardLoadAmount real
as
declare @Index smallint
declare @RecordAmount smallint
set @RecordAmount=(select count(*) from udsdt_TrainCarriageType)
if (@RecordAmount=0)
begin
set @Index=1
end
else
begin
set @Index=(select max(tctf_Index) from udsdt_TrainCarriageType)+1
end

declare @StandardLoadIndex smallint
set @StandardLoadIndex=(select tcslf_Index from udfdt_TrainCarriageStandardLoad where tcslf_StandardLoadAmount=@StandardLoadAmount)

declare @InsertStatement nvarchar(512)
set @InsertStatement='insert into udsdt_TrainCarriageType (tctf_Index,tctf_Name,tctf_StandardLoadIndex) values ('+convert(nvarchar(10),@Index)+','''+@Name+''','+convert(varchar(10),@StandardLoadIndex)+')'
execute(@InsertStatement)

go
FrameSniper 2008-09-24
  • 打赏
  • 举报
回复
我现在传递Real和bit都有问题

这个过程是传real的,解决了这个一会再问传bit的
昵称被占用了 2008-09-24
  • 打赏
  • 举报
回复
怎么没bit?
pt1314917 2008-09-24
  • 打赏
  • 举报
回复

--try:
create procedure udsp_InsertTrainCarriageType
@Name nvarchar(16),
@StandardLoadAmount real
as
declare @Index smallint
declare @RecordAmount smallint
set @RecordAmount=(select count(*) from udsdt_TrainCarriageType)
if (@RecordAmount=0)
begin
set @Index=1
end
else
begin
set @Index=(select max(tctf_Index) from udsdt_TrainCarriageType)+1
end
declare @StandardLoadIndex smallint
set @StandardLoadIndex=(select tcslf_Index from udfdt_TrainCarriageStandardLoad where tcslf_StandardLoadAmount=@StandardLoadAmount)
declare @InsertStatement nvarchar(512)
set @InsertStatement='insert into udsdt_TrainCarriageType (tctf_Index,tctf_Name,tctf_StandardLoadIndex) values ('+convert(nvarchar(10),@Index)+','''+@Name+''','+convert(nvarchar(10),@StandardLoadIndex)+')'
execute(@InsertStatement)

go

FrameSniper 2008-09-24
  • 打赏
  • 举报
回复
这个是俺的存储过程

create procedure udsp_InsertTrainCarriageType
@Name nvarchar(16),
@StandardLoadAmount real
as
declare @Index smallint
declare @RecordAmount smallint
set @RecordAmount=(select count(*) from udsdt_TrainCarriageType)
if (@RecordAmount=0)
begin
set @Index=1
end
else
begin
set @Index=(select max(tctf_Index) from udsdt_TrainCarriageType)+1
end
declare @StandardLoadIndex smallint
set @StandardLoadIndex=(select tcslf_Index from udfdt_TrainCarriageStandardLoad where tcslf_StandardLoadAmount=@StandardLoadAmount)
declare @InsertStatement nvarchar(512)
set @InsertStatement='insert into udsdt_TrainCarriageType (tctf_Index,tctf_Name,tctf_StandardLoadIndex) values ('''+convert(nvarchar(10),@Index)+''','''+@Name+''','''+convert(nvarchar(10),@StandardLoadIndex)+''')'
execute(@InsertStatement)

go

然后调用

execute udsp_InsertTrainCarriageType 'C64K',65.5

然后有这样的错误

服务器: 消息 8115,级别 16,状态 2,过程 udsp_InsertTrainCarriageStandardLoad,行 25
将 expression 转换为数据类型 nvarchar 时发生算术溢出错误。
jobine 2008-09-24
  • 打赏
  • 举报
回复
报的什么错误?我这边没问题。
sql server2008 rtm
dawugui 2008-09-24
  • 打赏
  • 举报
回复
bit
整型数据 1、0 或 NULL。

100肯定不对啦.
chenjunsheep 2008-09-24
  • 打赏
  • 举报
回复
没有问题,
有可能在储存过程中类型变换不对
wgzaaa 2008-09-24
  • 打赏
  • 举报
回复
create proc pro_test1 @1 bit,@2 real,@3 money as
select @1 [1],@2 [2],@3 [3]
---
exec pro_test1 1,100.98,54.5
--------------------------------
1 2 3
---- ------------------------ ---------------------
1 100.98 54.5000

(所影响的行数为 1 行)
水族杰纶 2008-09-24
  • 打赏
  • 举报
回复
if object_id('Test') is not null drop table test
go
create table Test(A bit,B real,C money)
go
if object_id('P_test') is not null drop Proc P_test
go
create proc P_test
@A bit,
@B real,
@C money
as
insert Test select @A,@B,@C
go
Exec P_test 1,100.98,54.5
select * from test
(1 row(s) affected)

A B C
---- ------------------------ ---------------------
1 100.98 54.5000

(1 row(s) affected)
昵称被占用了 2008-09-24
  • 打赏
  • 举报
回复
贴出错误信息,肯定不是传参数的问题
可能的话贴出存储过程代码,这样最直接
pl_mm 2008-09-24
  • 打赏
  • 举报
回复
可以,其他地方错了
fcuandy 2008-09-24
  • 打赏
  • 举报
回复
参数顺序如果是:
bit,real,money

bit,money,real

就不会错
昵称被占用了 2008-09-24
  • 打赏
  • 举报
回复
create proc pr_test 
@a bit,
@b real,
@c money
as

return
go


execute pr_test 1,100.98,54.5


没有问题
加载更多回复(2)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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