on 08-14-2018 4:07 PM
Tengo un query donde uno de los filtros es fecha y es un campo de usuario (U_U_fecha), el cual se creó como alfanumérico.
Dentro del query, se declaró como datetime. Al ejectuar el query y seleccionar la fecha, no me trae la información. Me la trae toda sin filtrar las fechas
Cambié el declare del campo y lo puse varchar, pero igual no me filtra la fecha.
En la base de datos de prueba, recreé el mismo ambiente pero creé el campo de usuario como fecha y al ejecutar el query me sigue pasando lo mismo
Adjunto query para ver si me pueden colaborar
SET ARITHABORT OFF
SET ANSI_WARNINGS OFF
SET CONCAT_NULL_YIELDS_NULL OFF
/* SELECT FROM [dbo].[ocls] x0 */
declare @Tipo varchar(50)
/* WHERE */ set @Tipo = /* x0.name */ '[%0]' /*
SELECT FROM [dbo].[oclg] x1 */
declare @FECHA DATETIME /*
WHERE */ set @FECHA = /* x1.u_u_fecha */ '[%1]'
/* SELECT FROM [dbo].[ousr] x2 */
declare @Ruta varchar(50) /*
WHERE */ set @Ruta = /* x2.u_name */ '[%2]'
select t4.U_NAME 'Ruta', t1.u_u_fecha 'F. Actividad', t1.ClgCode 'Actividad',t0.cardcode 'Codigo', t0.cardname 'Cliente', t0.Phone1 'Telefono', t0.Address 'Direccion', t3.descript 'Ruta', t2.Name 'Tipo', t1.details 'Detalle', T1.Notes 'Comentario'
from OCRD t0
inner join oclg t1 on t0.cardcode = t1.cardcode and t1.CntctType = 2
inner join ocls t2 on t1.CntctSbjct = t2.Code
left outer join oter t3 on t0.Territory = t3.territryID
inner join ousr t4 on t1.AttendUser = userid
where t2.Name = @Tipo or @Tipo = '' and (T1.u_u_fecha = @FECHA OR @FECHA = RTRIM(ISNULL('',''))) and t4.u_Name = @Ruta or @Ruta = ''
order by 2,8
Ya lo solucioné
Se modificó el WHERE
WHERE
(t2.Name = @Tipo or @Tipo = '') AND
(T1.u_u_fecha = @FECHA OR @FECHA = '') AND
(t4.u_Name = @Ruta or @Ruta = '')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
La misma solución pero un poco más elegante:
WHERE @Tipo IN (t2.Name,'')
AND @FECHA IN (T1.u_u_fecha, '')
AND @Ruta IN (t4.u_Name '')
Gracias Johan, si me parece más elegante y lo tomo en cuenta
User | Count |
---|---|
99 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.