none
Convertir fecha a numero en SQL

    Question

  • Tengo la siguiente sentencia:

    SELECT

    encabezado.terminal , clientes.nit , clientes.razon_social , clientes.direccion , clientes.ciudad , clientes.telefonos ,

    encabezado

    .numero , encabezado.mes , encabezado.espera , encabezado.fecha , encabezado.vencimiento , encabezado.vendedor ,

    encabezado

    .bodega , encabezado.valor , encabezado.descuento , encabezado.iva , encabezado.anulado , encabezado.retefuente ,

    encabezado

    .anticipoiva, detalle.cantidad, detalle.codtipounidad, kardex.peso, kardex.npaquetes, (encabezado.fecha - encabezado.vencimiento ) as

    dia

    FROM

    clientes LEFT OUTER JOIN factura1_2000 encabezado ON clientes.nit = encabezado.

    nit

    inner

    join factura2_2000 detalle on detalle.numero = encabezado.

    numero

    inner

    join kardex on kardex.referencia = detalle.referencia

    WHERE

    encabezado.anulado = 0 ORDER BY encabezado.

    numero

    deseo convertir ese alias "dia" a número para saber cual es la diferencia en días entre los campos (encabezado.fecha - encabezado.vencimiento ) no se como hacerlo, alguien me puede colaborar?

    Muchas gracias

     


    DAMIAN PEREZ ARROYAVE elmaestroperez.blogspot.com
    Wednesday, November 09, 2011 4:43 PM

Answers

  • I want to convert the alias "dia" with a number to know what is the difference in days between the fields (encabezado.fecha - encabezado.vencimiento) do not know how someone can help me?

    Hi maestroperez,

    What is the data type of encabezado.fecha and encabezado.vencimiento? If it’s a datetime data type, please use the DATEDIFF function to calculate the number of days between two datatime values:

    SELECT DATEDIFF(DAY,'20111110','20111114') AS 'dia'
    

    Reference: DATEDIFF (Transact-SQL)

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Get or Request Code Sample from Microsoft
    If you have any feedback, please tell us.

    • Edited by KJian_ Monday, November 14, 2011 2:19 AM
    • Proposed as answer by Naomi NModerator Monday, November 14, 2011 3:30 AM
    • Marked as answer by KJian_ Wednesday, November 16, 2011 8:15 AM
    Monday, November 14, 2011 2:19 AM

All replies

  • Hello,

    This is an English spooken forum, so please post you question in English or visit a Spanish forum: http://social.technet.microsoft.com/Forums/es-ES/categories


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing
    Wednesday, November 09, 2011 5:33 PM
  • I want to convert the alias "dia" with a number to know what is the difference in days between the fields (encabezado.fecha - encabezado.vencimiento) do not know how someone can help me?

    Hi maestroperez,

    What is the data type of encabezado.fecha and encabezado.vencimiento? If it’s a datetime data type, please use the DATEDIFF function to calculate the number of days between two datatime values:

    SELECT DATEDIFF(DAY,'20111110','20111114') AS 'dia'
    

    Reference: DATEDIFF (Transact-SQL)

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Get or Request Code Sample from Microsoft
    If you have any feedback, please tell us.

    • Edited by KJian_ Monday, November 14, 2011 2:19 AM
    • Proposed as answer by Naomi NModerator Monday, November 14, 2011 3:30 AM
    • Marked as answer by KJian_ Wednesday, November 16, 2011 8:15 AM
    Monday, November 14, 2011 2:19 AM