set variable from excel-file

  • In my query I want to make a selection of  data based on between dates.
    Baecause I don't want to change the query every time, I want to set the dates in an Excel-file and use these dates as variable in my SQL.
    Excel-field formatted as date : 05/02/2018

    script :
    declare @gromdate smalldatetime;
    set @fromdate = cast(('y:\concorde\xalwin\octopus\exportverkoopoctopus-datumselectie.xlsx[Sheet1$c1]')-2 as smalldatetime);
    print @fromdate

    error :
    Msg 245, Level 16, State 1, Line 2
    Conversion failed when converting the varchar value 'y:\concorde\xalwin\octopus\exportverkoopoctopus-datumselectie.xlsx[Sheet1$c1]' to data type int.

  • You need to use OPENQUERY or a linked server or SSIS or something like that to grab the data from Excel.  What you're trying to do is convert the actual file path to a date, which clearly isn't going to work.  Why don't you store the date in the database instead of in Excel?

    John

Viewing 2 posts - 1 through 1 (of 1 total)

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