How to get current month from filename and bulk insert from text file into table?

I set up some dynamic SQL to help my bulk copy data from a text file to a table.  This works fine for files that come in every day; I get the previous day’s data, based on the file name that’s placed
in the folder.  That’s why I’m using the ‘-1’.  The dates will look like this: '20140131', so I'm using type 112.
declare @fullpath1 varchar(1000)
select @fullpath1 = '''\\system.local\ms\london\FTP\' + convert(varchar, getdate()-1, 112) + '_INDEXPRICES_EOM.SPC'''
declare @cmd1 nvarchar(1000)
print (@cmd1)
select @cmd1 = 'bulk insert [dbo].[SB_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
print(@cmd1)
exec (@cmd1)
I think the syntax will be somewhat similar to this:
YEAR(date_column)=YEAR(getdate()) AND MONTH(date_column)=MONTH(getdate())
I’m not totally sure how to incorporate that into my current syntax.
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

I tried a couple versions of this.
Declare @StartDate Date, @EndDate Date
Select @StartDate = convert(varchar, getdate()-28, 112), @EndDate = convert(varchar, getdate()-1, 112)
BEGIN
declare @fullpath1 varchar(1000)
select @fullpath1 = '''\\ms\london\FTP\' + ''' between ''' + Convert(Varchar(10), @StartDate, 101) + ''' and ''' + Convert(Varchar(10), @EndDate, 101) + '''_SP.SPC'''
declare @cmd1 nvarchar(1000)
print (@cmd1)
select @cmd1 = 'bulk insert [dbo].[SPBMI_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
print(@cmd1)
exec (@cmd1)
END
Here’s the string:
bulk insert [dbo].[SPBMI_Monthly] from '\\ms\london\FTP\' between '02/03/2014' and '03/02/2014'_SP.SPC' with (FIELDTERMINATOR = '\t', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR='0x0a')
The error message I keep getting is:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'between'.
Msg 319, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
I feel like I’m already pushing this thing to the limit. 
Maybe this last part isn’t possible.
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

Similar Messages

  • How to get current month and last month dynamically??

    how to get current month and last month dynamically
    like
    month = getCurrentMonth();
    lastmonth = getcurrentMonth() -1;
    please help
    thanks

    hi :-)
    /* depracated but can be still useful */
    java.util.Date dtCurrent = new java.util.Date();
    int month = dtCurrent.getMonth();
    int lastmonth = dtCurrent.getMonth() - 1;
    System.out.println("* " + month);
    System.out.println("* " + lastmonth);
    /* better to use this one */
    Calendar cal = new GregorianCalendar();     
    int imonth = cal.get(Calendar.MONTH);
    int ilastmonth = cal.get(Calendar.MONTH) - 1;
    System.out.println("*** " + imonth);
    System.out.println("*** " + ilastmonth);
    regards,

  • How to get the source code of an HTML page in Text file Through J2EE

    How to get the source code of an HTML page in Text file Through J2EE?

    Huh? If you want something like your browser's "view source" command, simply use a URLConnection and read in the data from the URL in question. If the HTML page is instead locally on your machine, use a FileInputStream. There's no magic invovled either way.
    - Saish

  • How to get the source code of an HTML page in Text file Through java?

    How to get the source code of an HTML page in Text file Through java?
    I am coding an application.one module of that application is given below:
    The first part of the application is to connect our application to the existing HTML form.
    This module would make a connection with the HTML page. The HTML page contains the coding for the Form with various elements. The form may be a simple form with one or two fields or a complex one like the form for registering for a new Bank Account or new email account.
    The module will first connect through the HTML page and will fetch the HTML code into a Text File so that the code can be further processed.
    Could any body provide coding hint for that

    You're welcome. How about awarding them duke stars?
    edit: cheers!

  • HOW TO GET CURRENT MONTH ?

    HAI FRENZ...
    WE VE SY-DATUM TO GET CURRENT DATE BUT ITS LIKE
    FOR E.G., 10.09.2008
    LIKE THAT IS THEIR ANY OTHER WAY TO GET CURRENT MONTH LIKE SEPTEMBER AS MY VALUE...
    HELP ME...
    REGARDS
    MEENA

    Hi ,
    You can use :
          DATA: w_t247 TYPE t247,
            w_spras TYPE sy-langu VALUE 'E',
            w_month TYPE month.
          w_month = wa_final3-month+4(2).
    *the value of w_month will come from offset calculation of sy-datum.
          CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
            EXPORTING
              langu = w_spras
              month = w_month
            IMPORTING
              t247  = w_t247.
          month = w_t247-ltx.

  • How to get current month from BI 7

    Dear Expert,
    I am working on a BI 7 report and I need to restrict a key figure using the current month and previous month.
    Could you help me to find out how to do so?
    Thank you very much!
    Arthur

    if you want to make  2 diff rest key figures.
    check if you have current month variable under cal.month ,  if not create a variable( single, not range ) for current month
    and make a new selection take key fig and rest with current month. 
    and make a new selection and take the key fig and restrict with  current month variable keep off set as -1
    if you want to make only one restricted key fig  which shows both current and previous then.
    create a variable as range and write a exit code from  sy-datum ( take month and year ) as the high value and substract one and make it as low value.
    Hope this helps

  • How to get Current month last year sale in report

    HI,
              I would like to compare the sale value of a  month for any year.
    ie sale of the march month for this year ,previous year and a year before ..like that
    at least for two years..ie current and prvious year.
    how can i get it done in query?
    thnx

    Create three restricted key figures.
    In one restrict month by current month.
    In other use offset of -12 and -24 while restricting current month.

  • How to Get current month of the Calendar

    Hey everyone ,
    Starting to understand a bit APEX now , but i'm still missing some more accurante knowledges such as methods i could call Here is my problem :
    I have a drag and drop APEX Calendar , and everything is working just fine , under this calendar i decided to add a flash report , who is showing the current month work ,
    and who is refreshing each time i add a new work in my calendar : my question is , is there a method to call to get the month the calendar is displaying ? Because when i change my calendar to an older month i need the flash report to change too so i can displayed the information from the month the calendar is displaying
    Any help or advice from you will be very apreciated , i thank you in advance
    Brice

    Krishnamurthy has a workaround please see thread http://forums.oracle.com/forums/message.jsp?id=827915 for details
    Sunil.

  • How to get Current Background Job name and Job Count programmically?

    Hi all,
            I have a requirement wherein I need to get the Current Background Job name and Job Count in the program and store it in a custom table. In other words, whenever I schedule a particular program ( This is a Std program) in background, I need to update this table with the Job Name and Job Count. This will be used by another program later to read the Job Information from table TBTCO. TBTCO has key fields Job Name and Job ID. The sheduled program will be a SAP standard program and I'll be writing the logic to get the info in an Implicit Enhancement Spot.
    Is there anyway I can do this? Any FM to get this information?
    Thanks,
    Mahesh.

    Hey Adrian,
                             Thanks a lot. This is what exactly i was looking for. Appreciate it.
    Mahesh.

  • Getting random LCK_M_SCH_M on convert and bulk insert task

    I starting getting random LCK_M_SCH_M locks with huge wait time, which hung my etl proccess.
    The ssis package runs like this:
    I have 4 containers that run in parallel and do the same thing:
    -Convert a tab delimited file from unicode->utf8
    -Truncate the table (within a foreach loop)
    -Bulk insert the data
    Also transactionoption is set to NotSupported.
    What could be causing the lock?
    All foreach loops do not overlap ragarding tables/files.
    Do they contest somehow?
    Elias

    The truncate table command imposes the schema lock so you will have to not to run in parallel this task
    Arthur
    MyBlog
    Twitter

  • How to get plain old S-video and Composite out from a MBP?

    Hi,
    this question is about someone's MacBook Pro he newly bought with adapters to get both DVI and Svideo/Composite Out.
    He got Mini DisplayPort to DVI-D converter, and a DVI-I to video converter, that cannot be plugged into a DVI-D port. Apple removed the analog capability of its adapter, that's bad. But what's badder is there doesn't seem to have any Mini DisplayPort to Svideo/Composite adapter, as there was with previous generation machines.
    How can someone easily output analog video from MBP?

    In fact, I recognize that these standards are old, which doesn't mean they're not up-to-date. Similar example, VGA connector is old, but perfectly useful, even in 2009. I recently plugged a 22" LCD with VGA and DVI on the same computer (a bland desktop PC), and there was strictly no difference. Same color depth, same crisp display. Even looking at a corner with a magnifier, nothing was different.
    So, changing standards just for the sake of it doesn't make any sense.
    Agreed that, as a pro, Apple would like me to buy their pro line, but nowhere in the pro line does an easy solution exists for S-Video and composite out. The solution you posted exists, but is unwieldly and not neat at all, if it doesn't break the Mac's connector under its weight. If a manufacturer can do this kind of adapter, Apple can do it better, and make a bigger profit out of it.
    For the adapter you posted, I don't ever buy anything that is not at least Mac+Windows compatible, or at a minimum is open-source, so anyone with programming skills can make something. The manufacturer also doesn't give a clue on how this works. I guess some sort of virtual driver sits in the system as a virtual IEEE1394 port so any program requiring FW can work transparently. Still, incompatible with the OS that most manufacturer ship their new PCs with, poor commercial decision, wether you like the OS or not.
    Adding FW in the MB unibody design wouldn't have cost anout $30. Rather, we're talking about a 25 cents chip, a 25 cents connector, which they would have rounded up to $20 and still, that was present in previous-gen MB. After all, they are indeed selling a matte screen on the MBP 17" for $50 more, despite them removing a single piece of glass which may cost, well, let's be fair, $5 to manufacture? That's dishonest. And capitalistically justified.
    So far, choosing a Mac for one's needs is no easy task: older white MacBooks have the same power as unibodies, excellent connectivity, top notch transfer speeds, BUT are heavier, as not as ecologically friendly nor do they have future-proof RAM standard. The unibodies are sleekier, easily recycled and will be able to be upgraded in the near future BUT is most likely unable to use current devices and have slower transfer speeds.
    For Pro models, the newer ones have great efficiency, much power and flexibility with their dual GPU BUT lost the option of matte screen, although their other pro-oriented monitors still default to matte. Only the 17" has the option. If a pro already finds his 15,4" bulky and with ample reserve power, will he buy the bigger and heavier 17"? Probably not.
    I understand that Apple way of doing business is keeping only what's essential with no unnecessary options (I'm looking at you, Asus, with you at least 10 different versions of you netbook). But this time, not everyone can find what he or she wants in Apple's line of laptops, as opposed to the iPod thing, where virtually any possible preference is covered.

  • How to get value in previous column and another row from Matrix with Custom Code?

    I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
    This is example report:
    * I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
    * First value of Open is item field in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
    Detail for Red number:
    1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
    expression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
    2. tb_TOTAL1 group on item_part = 1
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
    3. tb_TOTAL2 group on item_part = 3 or item_part = 4
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
    4. tb_TOTAL3 group on item_part = 2
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
    5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
    expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
    My custom code:
    Dim Shared prev_close As Double
    Dim Shared now_close As Double
    Dim Shared now_open As Double
    Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
        now_close = TOTAL3 + NowOpening
        prev_close = now_close
        Return now_close
    End Function
    Public Function GetOpening(Month as String,NowOpen as Double)
        If Month = "1" Then
            now_open = NowOpen
        Else    
            now_open = prev_close
        End If
        Return now_open
    End Function
    Thanks alot for your help!
    Regards
    Panda A

    Looks okay to me.
    Perhaps the variables should be declared as public (?)

  • How to get current time and date??

    How to get current time and date from my PC time and date to the java application??
    i use java.util.* package but got error, that is:
    - java.util.* and java.sql.* class are match
    - abstract class cannot be instantiated
    so what can i do, pls guide...thanks...

    There is a method in the System class that will return the current system time. You could also instantiate a Date, Time, Timestamp, or Calendar object, all of which get created with the system time by default.
    Don't import *. Import the specific classes you need.
    Next time, post the actual text of the exceptions/compile errors. If you make people guess, most just won't bother.

  • How get all record from master and matching record from detail

    hi master
    sir i have master detail table
    i have many record in master table but some record in detail table how i get
    all record from master and matching record from detail
    such as
    select m.accid,m.title,d.dr,d.cr from master m, detail d where m.accid=d.accid
    this query not work that get only related record i need all record from master
    please give me idea
    thanking you
    aamir

    hi master
    sir i have master detail table
    i have many record in master table but some record in
    detail table how i get
    all record from master and matching record from
    detail
    such as
    select m.accid,m.title,d.dr,d.cr from master m,
    detail d where m.accid=d.accid
    this query not work that get only related record i
    need all record from master
    please give me idea
    thanking you
    aamir
    select m.accid,m.title,d.dr,d.cr
    from master m, detail d
    where m.accid=d.accid (+)The outer join operator (+) will get you all the details from master and any details from the detail if they exist, but the master details will still be got even if there are not details.
    Note: Oracle 10g now supports ANSI standard outer joins as in:
    select m.accid,m.title,d.dr,d.cr
    from master m LEFT OUTER JOIN detail d on m.accid=d.accid

  • How come although iPads are getting more powerful, the iOS apps from apple are so mediocre and just not that great? We spend all this money for the latest ipad and all we get is these $5 video and music apps from apple. Why create the iOS platform and onl

    How come although iPads are getting more powerful, the iOS apps from apple are so mediocre and just not that great? We spend all this money for the latest ipad and all we get is these $5 video and music apps from apple. Why create the iOS platform and only offer so so apps like IMovie and GarageBand ? While other developers are offering much better apps like pinnacle studio for video, Cubasis and Auria for music production, apple has not showed much growth in terms of innovation. While there's nothing wrong with making an app like GarageBand where "anyone " can make a song, how about something for real musicians or an app not so basic as it get for video editing? After spending 0ver $700 on an ipad I'd be willing to spend more than $5 for a better video or audio app.

    First, try a system reset although I can't give you any confidence.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  It could take well over an hour!  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.

Maybe you are looking for