Ver Mensaje Individual
  #9 (permalink)  
Antiguo 17/02/2013, 17:08
Pelao
 
Fecha de Ingreso: abril-2003
Mensajes: 260
Antigüedad: 21 años, 7 meses
Puntos: 1
Respuesta: optimizacion de consultas

como debería hacerlo?
asi, especificando mas valores en el select?

Código PHP:
$query "SELECT COUNT(eventid), eventtime, eventtypendx, devicename FROM events WHERE eventtypendx = '14' AND DATEDIFF(day, eventtime, getdate()) < 1 AND devicename LIKE '%inq%'"
$result mssql_query($query);
$count mssql_fetch_array($result); 

mi estructura de tabla es:

CREATE TABLE [dbo].[Events](
[EventId] [int] NOT NULL,
[EventTime] [datetime] NOT NULL,
[TenantNdx] [tinyint] NULL CONSTRAINT [DF_Events_TenantId] DEFAULT (0),
[IndivNdx] [smallint] NULL CONSTRAINT [DF_Events_UserId] DEFAULT (0),
[AccessVerNdx] [smallint] NULL CONSTRAINT [DF_Events_AccessVer] DEFAULT (0),
[HostNum] [smallint] NULL,
[PointAddr] [int] NULL CONSTRAINT [DF_Events_PointAddr] DEFAULT (0),
[SiteNum] [tinyint] NULL,
[EventTypeNdx] [tinyint] NULL,
[StatusByte] [tinyint] NULL,
[Priority] [tinyint] NULL,
[DistGroup] [tinyint] NULL,
[CellNdx] [smallint] NULL,
[DistMask] [tinyint] NULL,
[FloatValue] [float] NULL,
[TextField] [char](4) COLLATE Modern_Spanish_CI_AS NULL,
[ControlDescr] [char](4) COLLATE Modern_Spanish_CI_AS NULL,
[ControlSource] [char](4) COLLATE Modern_Spanish_CI_AS NULL,
[DeviceName] [varchar](16) COLLATE Modern_Spanish_CI_AS NULL,
[MessageText] [varchar](64) COLLATE Modern_Spanish_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Events] WITH CHECK ADD CONSTRAINT [FK_Events_EventTypes] FOREIGN KEY([EventTypeNdx])
REFERENCES [dbo].[EventTypes] ([EventTypeId])
GO
ALTER TABLE [dbo].[Events] CHECK CONSTRAINT [FK_Events_EventTypes]
GO
ALTER TABLE [dbo].[Events] WITH CHECK ADD CONSTRAINT [FK_Events_UserHistory] FOREIGN KEY([TenantNdx], [IndivNdx], [AccessVerNdx])
REFERENCES [dbo].[UserHistory] ([TenantNdx], [IndivNdx], [AccessVerId])
GO
ALTER TABLE [dbo].[Events] CHECK CONSTRAINT [FK_Events_UserHistory]

gracias nuevamente!
__________________
Bye!