Reputation: 497
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
Upvotes: 0
Views: 9191
Reputation: 1269463
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.
Upvotes: 3