How to enter the date you want in a .bat file - csv

So I have a .vbs file that converts an .xlsx file into an .csv file. I made a short .bat file that opens automatically the cmd and runs it without having to manually enter the command.
set "curpath=%cd%"
start conv.vbs %curpath%\file_date.xlsx %curpath%\Destination_date.csv
How can I modify it in order to manually introduce a date, when running the .bat that takes the source file as file_date(you introduced) and creates a Destination_date(you introduced).csv ?

Set the UserDate variable via prompt where [Variable]=[Prompt]
set /p CurrentDate=Enter existing date here:
set /p NewDate=Enter new date here:
then update your conv.vbs to take another parameter:
set "curpath=%cd%"
start conv.vbs %curpath%\%CurrentDate%.xlsx %curpath%\%NewDate%.csv
the /p flag tells the batch file to prompt the user
the value on the left side of the equal sign is the name of the variable your setting
the value on the right side of the equal sign is the message you are prompting the user with
The variables are referenced by surrounding the variable name with % ... %

Related

How to get user input from a bat file in sql server pdw?

I want to get user input from a batch file and then use the string entered by the user into a SQL file.
For example, I have a batch file called test.bat. When I execute that, I should be prompted to enter a value, and after entering that value it should be used in my SQL file.
How can I do that?
You should add at the top of your .bat file these tow lines which read user input for the two parameters you are using
set /p item=Enter item:
set /p cost=Enter cost:

How to extract data from excel file into database with dynamic file name SSIS

Can you guy please help?
I have a problem to load data from excel into database with dynamic file name in my source files.
For example, for this month, my filename is ABC 31122017.xlsx. I successfully loaded data from each tab in this excel file into database.
But how do I make it dynamic? For example next month I have excel file
ABC 31012018.xlsx. How to make the job dynamic to pick up the new file?
I able to put the date in variable, but I don't know how to proceed with the filepath in SSIS.
#[User::InputPath] + "ABC " + #[User::Report_DT_DDMMYYYY] + ".xlsx"
I used this in Expressions in the Connection already, set up ExcelFilePath, but it couldn't work.
As in Excel Source connector in SSIS, I already chose the 31122017.xlsx and chose the first tab. But after I put in the Expressions, it couldn't find the first tab I chosen already.
Please help me guys. Thank you.
May be below explanation will help you in overcome this issue (I have SSIS 2012) -
First SSIS variable will hold date value i.e., "20180218". Variable Name- TodayDate. This variable value will be change according to today date.
Second SSIS variable will hold FileName i.e., ""D:\SSIS\StackOverFlowTest1\InputFiles\AB " + #[User::TodayDate] + ".xlsx". Variable Name- FileNameExcel.
Create connection manager for excel and under its properties window change expressions and set ExcelFilePath to "FileNameExcel".
Change "Delay Validation" to True under "Data Flow Task" property.
Using a foreach:
Set up a string variable fileName (put in the actual file path / file name so you can develop your package.
Add a Foreach Loop (File Enumerator which is default)
Set Expression for Directory = #InputPath
Set Files to the proper mask for your excel file (i.e. "ABD *.xlsx")
Go to variable mappings and link to fileName
Add an Excel connection and connect to your actual file.
Set an expression on properties to ExcelFilePath = #fileName
Delay Validation
Develop your data flow(s) as normal.

SSIS - How to loop through files in folder and get path+file names and finally execute stored Procedure with parameter as Path + Filename

Any help is much appreciated. I am trying to create an SSIS package to loop through files in the folder and get the Path + filename and finally execute the stored proc with parameter as path+filename. I am not sure how to get the path+filename and insert the into the Stored proc as parameter. I have attached the screenshot for your reference:
Looks like you have the right idea in general and the link #Speedbirt186 provided has some good details but it sounds like there are a couple of nuances that I thought I might point out in regards to flow and variables.
The foreach loop can assign the entire path or the file name or file name & extension to a variable. The latter will be the most help in your case if you don't want to add a script task to split the Filename from the path. If you start by adding 5 variables to your project it will make it a little easier. 1 will be the Source Directory Path, another the Destination (Archive) Directory Path, and then 1 to hold the File Name and Extension assigned by the for each loop. Then 2 additional dynamic variables that simply combine the source directory and file name to get the source full path and the destination with file name to get the destination full path.
Next make sure you set up your database and Excel file connections. In your Excel file connection after setting it up go to Expressions in the properties window and set the "Connection String" property to SourceFullPath. This will tell the connection to change the file path at every iteration of your loop.
Now you just need to setup your loop etc. Add the fore each loop container setting a directory, filter, and choose File Name and Extension.
Now in the expression box on the collection page set the directory property to be that of your Source Directory variable.
The last part of the Fore each loop is to set your variable mappings to store the file name in your variable. so go to that tab choose your file name variable and set index to 0.
At this point you can add your data flow and setup your import just like you would with a normal file (note your default value for your file name parameter should be to an actual file with the structure you will want to import).
After your data flow drop in your Execute SQL task and set it up how you need. here is an example of direct input and you can see an easy way to reference a parameter is simply a question mark (?).
Next in your sql task setup your parameter mapping by adding in the details you need such as:
Now you are on to your file task. Drop your file task and setup as you desire, but choose your destination and source full path variables to tell the task which file to move.
that's it your are done. there is 1 more thing to note though. The way you have your precedence set in the image you posted you show going from your data flow to your sql and to your file task simultaneously. If your stored procedure relies on your file you may want to put it after your sql task. You can always change the constraint options to "completion" if you want to move the file even if your stored proc fails.
What you want to do is to create a variable in your package, call it something like Filename. In the Edit window of the Foreach you can configure that variable to be set (on the Variable Mappings page- set index to 0).
To create a variable, you will need to have the Variables window showing. Use the View menu to show it if it's not currently open.
Then when calling your stored procedure you can pass the then current value of the variable as a parameter.
This link might help: https://www.simple-talk.com/sql/ssis/ssis-basics-introducing-the-foreach-loop-container/

SSIS Foreach loop container dynamic file name and path , then unzip files

I have a folder having multiple files with the name as
P04_20140326_1234.zip
P04_20130324_58714.zip
P04_20130808_jurhet.zip
P04_20130815_85893.zip
etc
The name is in the format P04_systemdate_*.zip.
I want to pick the folder containing currentdate in the name and unzip it first and load the data from extracted file into the table.eg : file named as A.txt goes into table A, filenamed as B goes into table B and so on...
I guess you have already done the following:
Add a Data Flow
Inside the data flow, add a flat file source, and Ole_DB destination
Configure the flat file source to point to one of your files and connect all the appropriate columns so that data flows from file to database.
If all of this is already working, then let's do the For-Each loop
Create a variable (default to package root level) and call it CsvFileName of type string
Add a ForEach loop (not a For loop)
Change loop type to be a Foreach File Enumerator
Set your folder path and look for *.csv
Under Variable mappings, add the variable "User::CsvFileName" variable, and set the index to 0 - this means that all file names returned from the Foreach loop will show up in the variable.
In the Connection Managers (bottom) right click on the FlatFileSource, and choose properties
Set the DelayValidation to "True"
Click on Expressions, and then click on the ellipsis
Set the ConnectionString property to use the "CsvFileName" variable
Run it. This should load all files. Now, if you just want to restrict it to a date here's what you do:
Create a variable called "FilterDate"
Set the value to whichever date you want to set (20140322, for example)
In the ForEach loop, go to Collections, and then click on Expressions, then click the ellipsis
Set the FileSpec property to be "*" + #[User::FilterDate] + "*.csv"
Now it will only filter the files that you want.

Moving file in the same location different folder in SSIS

How can I move files from one folder to another folder in SSIS using File System Task?
Example:
Move
D:\Target_folder files into D:\Target_folder\Old
here all the files in Target_folder like .xls,.txt will move into Old.
You need to create a number of variables with datatype of string
name : value
dstDir : D:\Target_folder\Old
srcDir : D:\Target_folder
FileName :
srcPath : [this should be an expression concating srcDir and FileName]
dstPath :[this should be an expression concating dstDir and FileName]
You then add a for each loop container then double click on it to open up the editor and choose collections.
Make sure the enumerator is a foreach File Enumurator. Click on the Expressions ellipsis underneath this and set the Directory property to srcPath.
Go to Variable Mappings add the User::FileName variable to map to the 0 index.
Add a File System Task to the for each loop container.
Set the operation to Move file
set both IsDestinationPathVariable and IsSourcePathVariable to true and set the values for DestinationVariable to dstPath and the SourceVariable to srcPath.
This should enumerate for each file in the directory source directory and move it to your destination directory.