Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Query (https://www.clubdelphi.com/foros/showthread.php?t=74055)

Richard Lopez G 27-05-2011 22:32:15

Query
 
Estimados necesito una ayuda si es que se puede dar, he realizado un query con subconsultas mi pregunta es la siguiente mi query es este.

select r.*,(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Entrada'and [LogDate] ='2011/05/27')Entrada,--(select Top 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='InicioAlmuerzo'and [LogDate] ='2011/05/27')InicioAlmuerzo,
--(select Top 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='FinAlmuerzo'and [LogDate] ='2011/05/27')FinAlmuerzo,
(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Salida'and [LogDate] ='2011/05/27')Salida
FROM(SELECT [Cod_per] CodPers
,[Cod_Finger] FingerID
,[DNI_per] DNI
,[ApePat_per] ApellidoPaterno
,[ApeMat_per] ApellidoMaterno
,[Nom_per] NombrePersonal
--,[NomProy_per] Proyecto
--,[NomArea_per] Area
FROM T_Personal
where [NomProy_per] ='Nextel'---and NomArea_per = 'Comercial'
and Estado_per ='Activo')r
OrderBy r.ApellidoPaterno, r.ApellidoMaterno;

este son los datos que me arroja

CodPersCodFingerDNIApellPaternoApellMaternoNombreEntradaSalida85128343497746AburtoArellanoWilmer7:25:01NULL776340884398AltamiranoReateguiJose Luis7:23:14NULL7815143546007BacaDavilaVictor Hugo7:36:14NULL71327044026275BravoOrtizJaime Eusebio9:39:46NULL1515442786534CanalesCustodioCarlos Javier7:17:59NULL80927440857417CaveroLiviaDaniel Alonso7:20:35NULL

Sale que cuando me arroge los datos null yo quiero ponerle un texto que diga (No Digito huella).

A la espera de su ayuda si es que se puede realizar.

Gracias.

Richard Lopez G 27-05-2011 22:36:53

Query
 
1 Archivos Adjunto(s)
CodPersCodFingerDNIApellPaternoApellMaternoNombreEntradaSalida85128343497746AburtoArellanoWilmer7:25:01NULL776340884398AltamiranoReateguiJose Luis7:23:14NULL7815143546007BacaDavilaVictor Hugo7:36:14NULL71327044026275BravoOrtizJaime Eusebio9:39:46NULL1515442786534CanalesCustodioCarlos Javier7:17:59NULL80927440857417CaveroLiviaDaniel Alonso7:20:35NULL

oscarac 27-05-2011 22:38:49

hola

primedo dale una leida a la guia de estilos aqui
segnudo trata de usar los tag's al momento de colocar tus preguntas porque si no el codigo que colocas se ve desordenado


en lo que se refiere a tu consulta pordrias colocar algo asi como

Código Delphi [-]
 
Case when Isnull (TuCampo, 0) = 0 then "Sin Huella" else TuCampo end As Huella

esto lo colocas al momento de seleccionar el campo que contiene "la huella"

Casimiro Noteví 27-05-2011 22:50:47

Además de lo indicado por oscarac, no repitas hilos, creo que no has leído nuestras normas. Debes cumplirlas, gracias.






.

Richard Lopez G 27-05-2011 23:23:04

Query
 
En que parte de mi codigo pondria esta linea que me estas enviando .
CasewhenIsnull(TuCampo, 0)= 0 then "Sin Huella")r
Urgente.

Código SQL [-]
select r.*,(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Entrada'and [LogDate] ='2011/05/27')Entrada,--(select Top 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='InicioAlmuerzo'and [LogDate] ='2011/05/27')InicioAlmuerzo,
--(select Top 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='FinAlmuerzo'and [LogDate] ='2011/05/27')FinAlmuerzo,
(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Salida'and [LogDate] ='2011/05/27')Salida
FROM(SELECT [Cod_per] CodPers
,[Cod_Finger] FingerID
,[DNI_per] DNI
,[ApePat_per] ApellidoPaterno
,[ApeMat_per] ApellidoMaterno
,[Nom_per] NombrePersonal
--,[NomProy_per] Proyecto
--,[NomArea_per] Area
FROM T_Personal
where [NomProy_per] ='Nextel'---and NomArea_per = 'Comercial'
and Estado_per ='Activo')r
OrderBy r.ApellidoPaterno, r.ApellidoMaterno;

oscarac 27-05-2011 23:32:40

primero que nada USA LOS TAG's URGENTEEEEEEEEEEEEEEEE
luego
elimina todo lo que no sirve de tu query,

Código Delphi [-]
 
select r.*,(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Entrada'and [LogDate] ='2011/05/27')
Entrada,(selectTop 1 [LogTime]from History as h where [UserID]= r.FingerID AND [FKey]='Salida'and [LogDate] ='2011/05/27')Salida
FROM(SELECT [Cod_per] CodPers
,[Cod_Finger] FingerID
,[DNI_per] DNI 
,[ApePat_per] ApellidoPaterno 
,[ApeMat_per] ApellidoMaterno 
,[Nom_per] NombrePersonal 
FROM T_Personal 
where [NomProy_per] ='Nextel'and Estado_per ='Activo')r
OrderBy r.ApellidoPaterno, r.ApellidoMaterno;


tu Query esta muy complicado, quiza si analizas bien existen oyras maneras de hacer lo que quieres, segun entiendo, debes identificar las salidas verdad?, entonces lo que te dije mas o menos iria por aqui

algo asi
Código Delphi [-]
 
select Top 1 Case When isnull([LogTime],0) = 0 Then "Sin Huella" Else [LongTime] end 
from History as h
where ([UserID]=FingerID AND [FKey] = 'Salida' and [LogDate] = '2011/05/27')Salida

Richard Lopez G 28-05-2011 00:40:20

Query
 
Estimado me sale error cuando hago lo que me dices de poner en mi codigo lo recomendado por tu persona a la espera de tu ayuda.

El error que me sale esta al ultimo

Código SQL [-]
select r.*,(selectTop 1 CaseWhenisnull([LogTime],0)= 0 Then'Sin Huella'Else [LongTime] endfrom History as h 
where [UserID]= r.FingerID AND [FKey]='Entrada'and [LogDate] ='2011/05/27')Entrada,
(selectTop 1 CaseWhenisnull([LogTime],0)= 0 Then'Sin Huella'Else [LongTime] endfrom History as h 
where [UserID]= r.FingerID AND [FKey]='Salida'and [LogDate] ='2011/05/27')Salida
FROM(SELECT [Cod_per] CodPers
,[Cod_Finger] FingerID
,[DNI_per] DNI 
,[ApePat_per] ApellidoPaterno 
,[ApeMat_per] ApellidoMaterno 
,[Nom_per] NombrePersonal 
--,[NomProy_per] Proyecto 
--,[NomArea_per] Area 
FROM T_Personal 
where [NomProy_per] ='Nextel'---and NomArea_per = 'Comercial' 
and Estado_per ='Activo')r
OrderBy r.ApellidoPaterno, r.ApellidoMaterno;

Msg 207, Level 16, State 1, Line 2
El nombre de columna 'LongTime' no es vlido.
Msg 207, Level 16, State 1, Line 5
El nombre de columna 'LongTime' no es vlido.

Me sale el error lineas arriba

abelg 30-05-2011 14:42:27

Creo asi tendría que esta listo.

Código SQL [-]
select r.*,
           isnull((select Top 1 convert(varchar(30), [LogTime])
           from History as h 
           where [UserID]= r.FingerID AND [FKey]='Entrada'and [LogDate] ='2011/05/27'), 'No Digito Huella')  Entrada,
           isnull((select Top 1 convert(varchar(30), [LogTime])
           from History as h 
           where [UserID]= r.FingerID AND [FKey]='Salida'and [LogDate] ='2011/05/27'), 'No Digito Huella') Salida
FROM(SELECT [Cod_per] CodPers
,[Cod_Finger] FingerID
,[DNI_per] DNI
,[ApePat_per] ApellidoPaterno
,[ApeMat_per] ApellidoMaterno
,[Nom_per] NombrePersonal
--,[NomProy_per] Proyecto
--,[NomArea_per] Area
FROM T_Personal
where [NomProy_per] ='Nextel'---and NomArea_per = 'Comercial'
and Estado_per ='Activo')r
OrderBy r.ApellidoPaterno, r.ApellidoMaterno

Salu2

Richard Lopez G 30-05-2011 19:01:50

Query
 
Estimado muchas gracias me ayudastes mucho

Richard Lopez G 30-05-2011 20:34:08

Query_Color
 
Estimados alguien sabe por ahi que sin los valores de un query que me da el SQL lo puedo poner con colores los valores.

Seria una gran ayuda sisisisisisisisis

oscarac 30-05-2011 20:38:24

los valores de un query?
Si lo muestras en un grid como vi en la imagen puedes pintar las celdas o el texto de la celda del grid

revisa documentacion sobre OnDrawColumnCell

Casimiro Noteví 30-05-2011 20:53:28

Y preguntas distintas en hilos distintos. Recuerda nuestras normas.


La franja horaria es GMT +2. Ahora son las 09:50:58.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi