Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/03/2008, 17:27
pacotux
 
Fecha de Ingreso: febrero-2008
Mensajes: 15
Antigüedad: 16 años, 3 meses
Puntos: 0
Duda Procedimiento

Que tal tengo, tengo este procedimiento:


declare @mes varchar (30)
declare @anio varchar (5)
declare @sql nvarchar (1000)
set @mes = datepart ("m",?)
set @anio = datepart ("yyyy",?)
set @sql = 'insert into A4E_CuentaContable (reporteperiodo_id,concepto,
montomn,montome,montototal) select b.reporteperiodo_id,a.cuenta as concepto,b.montomn,b.montoME, ' + @mes + ' from tmp_a4e_cuentascontablesab a
inner join tmp_a4e_cuentacontable b on a.cuenta=b.concepto where anio =' + @anio + 'order by a.cuenta'
case @mes when datepart ("m",?)=1 then 'Enero'
when datepart ("m",?)=1 then 'Febrero'
when datepart ("m",?)=1 then 'Marzo'
when datepart ("m",?)=1 then 'Abril'
when datepart ("m",?)=1 then 'Mayo'
when datepart ("m",?)=1 then 'Junio'
when datepart ("m",?)=1 then 'Julio'
when datepart ("m",?)=1 then 'Agosto'
when datepart ("m",?)=1 then 'Septiembre'
when datepart ("m",?)=1 then 'Octubre'
when datepart ("m",?)=1 then 'Noviembre'
when datepart ("m",?)=1 then 'Diciembre'
else @mes

execute sp_executesql @sql

Lo que pasa es que ya exiten varibles en donde contiene la fecha entonce no se si con la funcion datepart me estraiga solo laparte que me interesa y guardarla en una variable asi como el uso del case no se si este correcto, ya que me manda un erro de :
[Microsoft][ODBC SQL Server Driver]Campo COUNT erróneo o error de sintaxis