Simple Query for Current Date help

  • I'm trying to create a DTS Package to run daily to export data from my SQL 2000 database to a CSV file.

    This is what I'm trying to accomplish:

    SELECT [dbo].[imitmidx_sql].[activity_cd] AS "activity_cd", [dbo].[imitmidx_sql].[activity_dt] AS "activity_dt", [dbo].[imitmidx_sql].[item_no] AS "item_no", [dbo].[imitmidx_sql].[item_desc_1] AS "item_desc_1"

    FROM [dbo].[imitmidx_sql]

    WHERE [dbo].[imitmidx_sql].[activity_dt] = '{%Current Date MM/DD/YYYY%}'

    The date must be in the MM/DD/YYYY format. I am having trouble get the correct t-sql date function to accomplish where is says: {%Current Date MM/DD/YYYY%}. Anyone able to help out?

  • you can try the following code instead

    '{%Current Date MM/DD/YYYY%}'

    Replace(convert(varchar(10),getdate(),110),'-','/')

    for example you will get for today the following format

    09/10/2009

    I hope it will work for you

  • Assuming your column [dbo].[imitmidx_sql].[activity_dt] is of a char(10) type, it should be more efficient to use

    SELECT CONVERT(CHAR(10),GETDATE(),101) instead of the replace and convert functions.

    However, you should think about storing date values in date format, since SQL Server usually performs better when dealing with date values.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • vallolet04, Thanks so much for your help. The query works perfect!

  • No problem Marker any thime

  • Lutz,

    Your query works as well. Since it seems more efficient I will use the query you specified instead.

    Ryan

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply