简体   繁体   中英

SQL Server: error converting data type varchar to numeric

Here is the situation. I have a SQL Server table that contains the following columns:

TaskOrder (varchar(50), null)
Labor (decimal(18,2), null)
LaborCLIN (varchar(50), null)

I am creating a stored procedure that passes in the parameter: @TaskOrder

I created a temp table as follows:

declare @miprfin table
(
    TaskOdr varchar(50),
    Labor decimal(18,2),
    LaborClin varchar(50)
)

When I run the following query:

insert into @miprfin
   select TaskOrder, LaborCLIN, sum(labor) as labor
   from MIPRFIN 
   where TaskOrder = @TaskOrder
   group by TaskOrder, LaborCLIN
   order by LaborCLIN

I get the following error message:

Msg 8114, Level 16, State 5, Line 404
Error converting data type varchar to numeric.

I do not see where it is trying to convert any data.

I am using SQL Server 2012 Management Studio

You should always put the columns in an insert , and this is why:

insert into @miprfin(TaskOdr, LaborCLIN, Labor)
    select TaskOrder, LaborCLIN, sum(labor) as labor
    from MIPRFIN 
    where TaskOrder = @TaskOrder
    group by TaskOrder, LaborCLIN
    order by LaborCLIN;

You were putting labor into the laborclin field and vice versa. Hence the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM