请帮我看看我写的先进先出法存储过程有问题吗?

wy_whb 2003-08-22 12:26:29
我写一个先进先出法的存储过程,然后调用提示:将数据类型 nvarchar 转换为 datetime 时出错,请大家帮我看看,问题出在什么地方!以下是存储过程:
CREATE PROCEDURE [FIFO_Out_Price_p]
@Mat_ID varchar(50),
@Outing numeric(18,3),
@Date DateTime,
@IOFlag varchar(2),
@OutPrice money output
AS

declare @Outed numeric(18,3)
declare @Inted numeric(18,3)
declare @matid varchar(50)
declare @Count numeric(18,3)
declare @Money money
declare @Price money
declare @InitPrice money
declare @InitCount numeric(18,3)
declare @IsInit bit
declare @Flag bit

set @Outed = 0
set @Inted = 0
set @Count = 0
set @Money = 0
set @Price = 0
set @InitCount = 0
set @IsInit = 0
set @Flag = 0

if @Outing = 0
begin
-- select 0 as Price
set @OutPrice = 0
return
end
if @IOFlag = 'O'
select @Outed = sum(isnull(data_count, 0)) from iobill_det_tb
where (io_flag = -1) and (iob_spec_time <= @Date) and (material_id = @Mat_ID)
else if @IOFlag = 'I'
begin
declare Count_Cur cursor for
select distinct b.child_id, sum(isnull(b.dosage * a.data_count, 0))
from iobill_det_tb a
join bom_det_tb b
on a.material_id = b.mat_id
where b.child_id = @Mat_ID and io_flag = 1 and (iob_spec_time <= @Date)
group by b.child_id
open Count_Cur
fetch next from Count_Cur into @matid, @Outed
close Count_Cur
deallocate Count_Cur
end

if @Outed is null
set @Outed = 0
if @IOFlag = 'O'
declare in_cur cursor for
select data_count, unitprice from iobill_det_tb
where (io_flag = 1) and (material_id = @Mat_ID)
order by iob_spec_time
else if @IOFlag = 'I'
declare in_cur cursor for
select data_count, UnitPrice from iobill_det_tb
where material_id = @Mat_ID and io_flag = -1
order by iob_spec_time
open in_cur
fetch next from in_cur into @Count, @Price
while @@FETCH_STATUS = 0
begin
set @Inted = @Inted + @Count
if (@Outed <= @Inted)
begin
if (@IsInit = 0)
begin
set @InitPrice = @Price
set @InitCount = @Count - @Outed
set @Money = @Money + @InitPrice * @InitCount
set @IsInit = 1
end

if (@Outed + @Outing <= @Inted)
begin
set @Flag = 1
set @Money = @Money + @Price * (@Outing - @InitCount)
break
end
if (@Flag = 0) and (@IsInit = 1) and (@Outing - @InitCount - @Count > 0)
begin
set @Money = @Money + @Price * @Count
set @InitCount = @InitCount + @Count
end

end
fetch next from in_cur into @Count, @Price
end
close in_cur
deallocate in_cur
if ((@IsInit = 0) or (@Flag = 0)) and (@IOFlag = 'O')
raiserror('库存不够,请您核查!', 16, 1)
set @OutPrice = @Money / @Outing
return
go

以下是调用的语句:
declare @p money
exec fifo_out_price_p '03011', 150, getdate, 'I', @p output

提示错误:
将数据类型 nvarchar 转换为 datetime 时出错。

...全文
54 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lfangxiao 2003-08-22
  • 打赏
  • 举报
回复
getdate是一个函数,应该这样写:

exec fifo_out_price_p '03011', 150, getdate(), 'I', @p output

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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