Problem with dates | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Problem with dates

Hello, i have this issue with dates, i dont know how to ask user for a date to make a search in the table i have this script:
SELECT Personal.EmpID AS Reloj, Personal.EmpApPaterno + ‘ ‘ + Personal.EmpApMaterno + ‘ ‘ + Personal.EmpNombre AS Nombre, Personal.FechaIngreso AS F_Ingreso, wk4_Ultimo_Turno_Empleados_Activos.Turno, wk4_Ultima_Area_Empleados_Activos.Area
FROM (Personal INNER JOIN (wk4_Ultima_Area_Empleados_Activos INNER JOIN wk4_Ultimo_Turno_Empleados_Activos ON wk4_Ultima_Area_Empleados_Activos.EmpID = wk4_Ultimo_Turno_Empleados_Activos.EmpID) ON Personal.EmpID = wk4_Ultima_Area_Empleados_Activos.EmpID) INNER JOIN wk4_UltimoPuestoC1 ON wk4_Ultimo_Turno_Empleados_Activos.EmpID = wk4_UltimoPuestoC1.EmpID
WHERE ((Personal.FechaIngreso Between convert(datetime,Fecha_Inicial) And convert(datetime,Fecha_Final)) AND Personal.Activo=’S’)
ORDER BY Personal.FechaIngreso DESC;
but in convert(datetime,fecha_final) and convert(datetime,fecha_inicial) returns an error:
Msg 243, Level 16, State 1, Line 1
Type Fecha_Inicial is not a defined system type.
Msg 243, Level 16, State 1, Line 1
Type Fecha_Final is not a defined system type.
I know that those two are not system types, but how can i do the equivalent to the access function:
Format([Fecha_Inicial],"mm/dd/yyyy") and Format([Fecha_Final],"mm/dd/yyyy")
that seeks particular dates inputed by useres in a table?
can somebody help me please?
thanks Love… how is it?
It is a common misconception to think DATETIME values in SQL Server are stored in any particular format. They are not. Internally a value in a DATETIME column is stored as 4 integers representing DATE and TIME. Check this out:
http://www.sql-server-performance.com/fk_datetime.asp
http://www.karaszi.com/SQLServer/info_datetime.asp
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
]]>