sql server - Conversion failed when converting datetime from character string while procedure execution -


i need favor on resolve conversion issue.the code have

alter procedure [workflow_app].[diagnosiscd_car]         @v_monthstr    char ,         @v_monthend    char ,         @v_year        char ,         @v_state_cd    char ,         @v_claim_key   char ,         @v_contractor  char  declare @v_makedatestr   varchar(10) declare @v_makedateend   varchar(10)  select @v_makedatestr  = '01-' + @v_monthstr + '-' + @v_year select @v_makedateend  = '01-' + @v_monthend + '-' + @v_year   select @v_datebegin  = convert(datetime, @v_makedatestr,105)----error select @v_dateend  = dateadd(d, -day(dateadd(m, 1, convert(datetime, @v_makedateend ,105))), dateadd(m, 1, convert(datetime, @v_makedateend ,105)))---error 

this code formed using tool , changed somewhere manual.

i getting

'conversion failed when converting datetime character string.'

at "error" comment.

i tried using convert, cast functions unable resolve.

any 1 suggest error , write appropriate conversion code error.

i converting oracle stored procedure sql server 2005.

i using sql server management studio express 2005.

what wrong above code , correct code ?

any code ? ????////// correct conversion

the way converting string datetime can lead different results in case run script in server different culture related settings.

for datetime(s) string, recommend follow rule of building string starting year, month, , on... yyyy-mm-dd.

select @v_makedatestr  = @v_year + '-' + @v_monthstr + '-01'  select @v_makedateend  = @v_year + '-' + @v_monthend + '-01'  

then cast:

cast(@v_makedatestr datetime); cast(@v_makedateend datetime); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -