简体   繁体   中英

Can't execute store procedure in rails console (activerecord-sqlserver-adapter)

I'm using rails console trying to execute the following store procedure:

exec dbo.MP_RPT_Q_VENTAS_TOP_PRODUCTOS @COD_CTE='',@COD_DOC='T',@FECHA1='2015-01-01',@FECHA2='2015-23-06',@COD_GRUPO='',@COD_ZONA='',@PORCENTAJE=30,@DESCRI='',@MIN='X',@CONTADO='',@COD_AGRICOLA='',@COD_GRUPO_PROD_INTERES='',@UTILIDAD_MAXIMA='101',@CATEGORIA='',@FILTRAR_VALOR='C',@CODIGO_INGREDIENTE_ACTIVO='',@CODIGOS_PRODUCTOS='',@CLASIFICACION='T',@ORDEN='$UTILIDAD',@FORMATO_ASP='0',@CLASIFICACION2='T',@CLASIFICACION3='T',@TIPO_CLIENTE='TODOS',@COD_LOTE=''

To do so, I'm running the following command, note that I striped the parameters and only left the values:

Almacen.execute_procedure("MP_RPT_Q_VENTAS_TOP_PRODUCTOS", '','T','2015-01-01','2015-23-06','','',30,'','X','','','','101','','C','','','T','$UTILIDAD','0','T','T','TODOS','')

When I try to run that line, I get the following error:

TinyTds::Error: The conversion of a varchar data type to a smalldatetime data ty
pe resulted in an out-of-range value.: EXEC MP_RPT_Q_VENTAS_TOP_PRODUCTOS '', 'T
', '2015-01-01', '2015-23-06', '', '', 30, '', 'X', '', '', '', '101', '', 'C',
'', '', 'T', '$UTILIDAD', '0', 'T', 'T', 'TODOS', ''
ActiveRecord::StatementInvalid: TinyTds::Error: The conversion of a varchar data
 type to a smalldatetime data type resulted in an out-of-range value.: EXEC MP_R
PT_Q_VENTAS_TOP_PRODUCTOS '', 'T', '2015-01-01', '2015-23-06', '', '', 30, '', '
X', '', '', '', '101', '', 'C', '', '', 'T', '$UTILIDAD', '0', 'T', 'T', 'TODOS'
, ''
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-sqlserver-adapt
er-4.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:
96:in `each'
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-sqlserver-adapt
er-4.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:
96:in `block in execute_procedure'

...

I tried changed by changing those dates by stripping quotes between them, and the store is executed, but with no results, which is not correct.

Any ideas?

Error: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value

This type of error indicates that you pass date in different format that DB expects. For instance:conversion string '2015-23-06' to SMALLDATETIME fails when the format is YEAR-MONTH-DAY. There is no month 23.

Possible solutions:

  • provide arguments in correct dateformat '2015-06-23'
  • change dateformat SET DATEFORMAT ydm

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