0

我的 SQL Server 数据库中有错误

varchar将数据类型转换为浮点数时出错。

我的桌子在下面。我想要解决这个问题。

错误在线

ROUND(REPLACE(CalvedF,''*'',''''),0) AS [Calved]

表结构:

CREATE TABLE [dbo].[NonPedigreeBovinesDairy](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Date] [datetime] NULL,
    [Upto3MonthsM] [varchar](50) NULL,
    [Over3monthsupto6monthsM] [varchar](50) NULL,
    [Over6monthsupto12monthsM] [varchar](50) NULL,
    [Over12monthsupto16monthsM] [varchar](50) NULL,
    [Over16monthsupto20monthsM] [varchar](50) NULL,
    [months20andoverM] [varchar](50) NULL,
    [upto3monthsF] [varchar](50) NULL,
    [Over3monthsupto6monthsF] [varchar](50) NULL,
    [over6monthsupto12monthsF] [varchar](50) NULL,
    [over12monthsupto16monthsF] [varchar](50) NULL,
    [over16monthsupto20monthsF] [varchar](50) NULL,
    [months20andoverF] [varchar](50) NULL,
    [calvedF] [varchar](50) NULL,
 CONSTRAINT [PK_NonPedigreeBovinesDairy] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

程序是:

if @CatId = 3          
Begin            

if @gender = 'Male'            
Begin          
SET @cmd = 'SELECT id, DATENAME(month,[Date]) + '' '' + CAST(YEAR([Date]) AS VARCHAR(4)) AS Monthyear,           
Day([Date]) AS [DayNo],           
ROUND(REPLACE(Upto3MonthsM,''*'',''''),0) AS [Upto 3 Months],          
ROUND(REPLACE(Over3monthsupto6monthsM,''*'',''''),0) AS [Over 3 months upto 6months],          
ROUND(REPLACE(Over6monthsupto12monthsM,''*'',''''),0) AS [Over 6 months upto 12 months],           
ROUND(REPLACE(Over12monthsupto16monthsM,''*'',''''),0) AS [Over 12 months upto 16months],          
ROUND(REPLACE(Over16monthsupto20monthsM,''*'',''''),0) AS [Over 16 months upto 20 months],          
ROUND(REPLACE(months20andoverM,''*'',''''),0) AS [Months 20 and over]          
FROM NonPedigreeBovinesDairy WHERE CAST(YEAR([Date]) AS VARCHAR(4)) ='+@lastyears+''            
EXEC sp_executesql @cmd            
End          

if @gender = 'FeMale'            
Begin       
SET @cmd = 'SELECT id, DATENAME(month,[Date]) + '' '' + CAST(YEAR([Date]) AS VARCHAR(4)) AS Monthyear,           
 Day([Date]) AS [DayNo],           
 ROUND(REPLACE(Upto3monthsF,''*'',''''),0) AS [Upto 3 months],          
 ROUND(REPLACE(Over3monthsupto6monthsF,''*'',''''),0) AS [Over 3 months upto 6 months],          
 ROUND(REPLACE(Over6monthsupto12monthsF,''*'',''''),0) AS [Over 6 months upto 12 months],
 ROUND(REPLACE(Over12monthsupto16monthsF,''*'',''''),0) AS [Over 12 months upto 16 months],          
 ROUND(REPLACE(Over16monthsupto20monthsF,''*'',''''),0) AS [Over 16 months upto 20 months],
 ROUND(REPLACE(CalvedF,''*'',''''),0) AS [Calved]          
 FROM NonPedigreeBovinesDairy WHERE CAST(YEAR([Date]) AS VARCHAR(4)) = '+@lastyears+''            
EXEC sp_executesql @cmd   
End          

End   
4

0 回答 0