sql - "Error converting data type nvarchar to numeric." -
i'm trying create function returns table bunch of fields. query used in function inserts data temp table inserts returning table. query runs fine when run outside of function when select function "error converting data type nvarchar numeric." error.
the structure returning table same table selects , inserts returning table. below how function defined
alter function [dbo].[func_prescriberdata](@networkid bigint, @startdate datetime, @enddate datetime) returns @rtntable table ( name nvarchar(1000) null,clinicid int null ,networkprescriberid int null,guidemedpatients int null, inactivepatients int null,avgage decimal null,avgphqscore decimal null, [%riskassessmenthigh] varchar(10) null ,[%riskassessmentmoderate] varchar(10) null,[%riskassessmentlow] varchar(10) null, toxicologytests int null,[%consistentresults] varchar(10) null, [%alcohol] varchar(10) null,[%negativeprescribed] varchar(10) null ,[%illicit] varchar(10) null,totalpdmps int null,[%aberrantresults] varchar(10) null, csareviewed int null,type nvarchar(1000) null ,medlesstan15 int null,between15and59 int null,between60and100 int null,between101and500 int null,greaterthan500 int null, avgmed decimal null, [bh/am] int null,opiodsbelowthreshold int null,opioidprescreening int null,sedativesantianxiety int null,stimulants int null,other int null) begin declare @temptable table ( name nvarchar(1000) null,clinicid int null ,networkprescriberid int null,guidemedpatients int null, inactivepatients int null,avgage decimal null,avgphqscore decimal null, [%riskassessmenthigh] varchar(10) null ,[%riskassessmentmoderate] varchar(10) null,[%riskassessmentlow] varchar(10) null, toxicologytests int null,[%consistentresults] varchar(10) null, [%alcohol] varchar(10) null,[%negativeprescribed] varchar(10) null ,[%illicit] varchar(10) null,totalpdmps int null,[%aberrantresults] varchar(10) null, csareviewed int null,type nvarchar(1000) null ,medlesstan15 int null,between15and59 int null,between60and100 int null,between101and500 int null,greaterthan500 int null, avgmed decimal null, [bh/am] int null,opiodsbelowthreshold int null,opioidprescreening int null,sedativesantianxiety int null,stimulants int null,other int null) insert @temptable ( name ,clinicid,networkprescriberid,guidemedpatients, inactivepatients ,avgage ,avgphqscore ,[%riskassessmenthigh],[%riskassessmentmoderate] ,[%riskassessmentlow] ,toxicologytests ,[%consistentresults], [%alcohol] ,[%negativeprescribed] ,[%illicit],totalpdmps ,[%aberrantresults], csareviewed ,type,medlesstan15,between15and59,between60and100,between101and500,greaterthan500,avgmed,[bh/am],opiodsbelowthreshold,opioidprescreening,sedativesantianxiety,stimulants,other
it's hard tell issue above script i'm looking way debug issue is. strange thing function runs fine if change 1 of parameters (change networkid) supposed return data in same format.
can me point look?
thanks,
i've found link post entire sql script. can found here
check columns inserted decimal
column, in example avgage
, avgphqscore
i guessing there whitespace or special character original nvarchar
column, brings error.
the easiest way check trying locate 2 columns mapped avgage
, avgphqscore
, run following statements check whether values nvarchar
column implicitly converted decimal
:
select original_nvarchar_column table isnumeric(original_nvarchar_column) = 0
if returns, means not value nvarchar
column converted decimal
, , result in issue got.
wiki
Comments
Post a Comment