字段数据类型问题ing
alter proc proc_yewu_updown
@dest_id varchar(20),
@start_time char(11),
@end_time char(11),
@total_up int output,
@total_down int output,
@total_money int output,
@total_order int output
as
declare @first_time varchar(20),@last_time varchar(20),@m int
declare @min_up_number int,@max_up_number int,@min_down_number int,@max_down_number int
declare @up_number int,@down_number int,@fee_total int
declare @number int,@sql nvarchar(4000),@flag bit,@order_number int
declare @par nvarchar(4000),@p varchar(8000),@n int
set @total_order=0
set @fee_total=0
set @total_up=0
set @total_down=0
set @total_money=0
set @start_time=substring(@start_time,1,4)+substring(@start_time,6,2)+substring(@start_time,9,2)
set @end_time=substring(@end_time,1,4)+substring(@end_time,6,2)+substring(@end_time,9,2)
set @first_time=@start_time
set @last_time=@end_time
while cast(@first_time as int) <= cast(@last_time as int)
begin
select @sql='select @n=count(name) from sms_data..sysobjects where name=@name and type=''U'''
select @par='@n int out,@name varchar(4000)'
select @p='Submit'+@first_time
execute sp_executesql @sql,@par,@n out,@p
if @n=0 ---'no extst'
set @first_time=@first_time +1
else ---'extst'
begin
set @sql=N'select @number=count(*) from sms_data.dbo.Submit'+@first_time +' where dest_id = ' +@dest_id
exec sp_executesql @sql,N'@number int output',@min_up_number output
set @first_time=@first_time +1
set @total_up=@total_up + @min_up_number
-- print @max_down_number
end
end
-- exec proc_yewu_updown '0189805', '2003-09-01','2003-10-15',0,0,0,0
在这条: set @sql=N'select @number=count(*) from sms_data.dbo.Submit'+@first_time +' where dest_id = ' +@dest_id
为什么我加上where条件就出错。将 varchar 值 '01898***' 转换为数据类型为 int 的列时发生语法错误。其中dest_id是varchar(20),在表中长度不同