none
Set a default value in a table with only 1 field named "DateToday" RRS feed

  • Question

  • In an SQL server database, I have a table named "DateToday" with only 1 field with the same name, I want that field to show the actual date in the format of 2013-11-02 automatically when a connection is made to that database, how can I achieve that?

    I am new to SQL and I have to begin somewhere, thank you all for your time.

    Note: I am using this field in my Access database that is linked to that table to verify that the licence is not expired for my application.

    Claude


    Claude Larocque

    samedi 2 novembre 2013 05:37

Réponses

  • Hi

    You are on French MSDN forums, so please use French.

    As an answer to your question please consider the following:

    DateTime format depends on SQL Server local settings. So, if this format is mandatory, you can use a varchar field.

    SQL is a server and it does not push data to the client, the client requests for data. But the same is for access.

    I assume you have something like a Form, where you run a "select * from DateToday" and compare the result.

    A view might be usefull here

    create view DateToday as 
    select replace (convert(varchar(20), GETDATE(),  111) , '/', '-')  as DateToday
    
    
    select  *from  DateToday

     This will return always the current date in the requested format.

    Here you have details about what 111 means :

    http://msdn.microsoft.com/fr-fr/library/ms187928.aspx

    Regards,


    Aurel BERA, MSFT
    MSDN Community Support. LE CONTENU EST FOURNI "TEL QUEL" SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE.
    S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution.


    mercredi 6 novembre 2013 12:57

Toutes les réponses

  • Hi

    You are on French MSDN forums, so please use French.

    As an answer to your question please consider the following:

    DateTime format depends on SQL Server local settings. So, if this format is mandatory, you can use a varchar field.

    SQL is a server and it does not push data to the client, the client requests for data. But the same is for access.

    I assume you have something like a Form, where you run a "select * from DateToday" and compare the result.

    A view might be usefull here

    create view DateToday as 
    select replace (convert(varchar(20), GETDATE(),  111) , '/', '-')  as DateToday
    
    
    select  *from  DateToday

     This will return always the current date in the requested format.

    Here you have details about what 111 means :

    http://msdn.microsoft.com/fr-fr/library/ms187928.aspx

    Regards,


    Aurel BERA, MSFT
    MSDN Community Support. LE CONTENU EST FOURNI "TEL QUEL" SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE.
    S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution.


    mercredi 6 novembre 2013 12:57
  • Merci Aurel,

    Exactement ce dont j'avais besoin, en créant cette vue, j'ai pu refaire le code pour être fonctionnel.

    Super!

    Claude


    Claude Larocque

    mercredi 6 novembre 2013 19:50