Msg 248, уровень 16, состояние 1, строка 26 преобразование значения varchar '3502033000' переполнило столбец int.
ALTER PROCEDURE [dbo].[SP_GetAmountByGLCode] -- EXEC SP_GetAmountByGLCode '','',50,'','','1501102000' @FromDate nvarchar(50), @ToDate nvarchar(50), @PaidStatus int, @UlbCode varchar(10), @filenumber varchar(100), @GLCODE varchar(100) AS SET NOCOUNT ON; BEGIN --SET FMTONLY OFF; declare @strSql nvarchar(max) set @strSql = 'select ud.UlbCode as PlaceName, rf.GlCode, CAST(Convert(decimal(18,2), SUM(id.Amount)) as varchar(50)) as [TotalAmount] from RequestFee rf, InvoiceDetail id, Invoice i, UlbData ud, PlanRequest pr, ScrutinyRequest sr, Place p, Fee f where i.PlanRequestId = pr.PlanRequestId and rf.PlanRequestId = pr.PlanRequestId and pr.PlanRequestId = sr.PlanRequestId and sr.ParentUlbId = ud.PlaceId and p.PlaceId = sr.ParentUlbId and p.PlaceId = ud.PlaceId and i.InvoiceId = id.InvoiceId and id.RequestFeeId = rf.RequestFeeId and f.FeeId = rf.FeeId and f.IsDeleted = ''N'' and i.IsDeleted = ''N'' and rf.GLCODE != 1401201012 ' IF (@FromDate = '' OR @FromDate is null) BEGIN set @FromDate = '05-16-2018' print @FromDate END IF (@ToDate = '' OR @ToDate is null) BEGIN set @ToDate = CAST(GETDATE() as nvarchar(50)) print @ToDate END -- ' + convert(int, @UlbCode) + '' set @strSql = @strSql + 'and CONVERT(date, i.PaidDate) >= cast(''' + @FromDate + ''' as date) ' + 'and CONVERT(date, i.PaidDate) <= cast(''' + @ToDate + ''' as date) ' + 'and i.PaidStatusId = ' + convert(varchar(10), @paidstatus) PRINT @UlbCode IF (@UlbCode <> '' OR @UlbCode <> null) BEGIN set @strSql = @strSql + ' and ud.UlbCode = cast(''' + @UlbCode + ''' as int) ' END IF (@GLCODE <> '' OR @GLCODE <> null) BEGIN set @strSql = @strSql + ' and rf.GlCode = ''' + @GLCODE + '''' END IF (@filenumber <> '' OR @filenumber <> null) BEGIN set @strSql = @strSql + ' and sr.ScrNo = ''' + @filenumber + '''' END set @strSql = @strSql + ' group by ud.UlbCode,rf.GlCode order by ud.UlbCode,rf.GlCode' --return exec sp_Executesql @strSql declare @t table (PlaceName varchar(50), GlCode varchar(50), TotalAmount varchar(50) ); insert into @t exec sp_Executesql @strSql; select PlaceName as [ULB],GlCode as [GLCode],TotalAmount as [Amount] from @t; END
Что я уже пробовал:
как решить,я пробую все объявления в bigint и long из int