Database Project - how can I access SQLCMD Variables in the Post build event command line - sqlcmd

I've got a database project that I'm wanting to have call a batch file in the post-build event. So far that's pretty simple, but I want to be able to set some variables in the SQLCMD Variables section of the project, then pass those variables as arguments to the batch file.
When I reference any of my user-defined SQLCMD variables in my post-build event, they're just empty strings.
As an example, if I create a SQLCMD variable called $(MyVariable) and give it a default value of ABC, I try referencing it when calling my batch file with :
call <path and name of batch file> $(MyVariable)
and the parameter is empty.
Is there a way that I can do this?

Related

TCL - Reading console output (not keystrokes)

So I am very new to TCL commands and I have to write a simple query which would read the hash value generated by a command.
TCL query is part of a bigger script where we need to generate a hash value using tcl command.
Below is the whole scenario:
Basically, need to execute a command to generate HASH value.
For ex:
request password-hash -password <password_value>
Once above command is executed, the shell will provide a hash value. This hash value then should be provided to another command.
For ex:
set password-hash <above generated value here>
After a lot of searching I think exec command will give the hash as output, I was then planning to store it in some variable using set command, something like below:
set hash_value [exec request password-hash -password <password_value>]
& then
set password-hash $hash_value
however, I am facing error that tcl evaluation failing.
The script 'set hash_value [exec request password-hash -password <password_value>];' evaluation failed. Error: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
Is exec command correct way of doing the what I actually wanted to do?
Since evaluation is failing, I think some syntax issue is there maybe?
Any better way to read console output and provide it as input to another command?
Thanks!!

How to pass azure pipeline variable to mysql stored procedure query in look up activity

I have to call a stored procedure in lookup activity of Azure Data Factory for mysql that takes azure pipeline variable as input but i dont know the exact syntax.
Like call stored_prpcedure("#variables('BAtchID')")
The variable is of string type
If anyone knows how exactly i can call it?
Please do share.
You cannot directly use call stored_prpcedure("#variables('BAtchID')") in your query section of Look up activity.
The query field expects a string value, when you use call stored_prpcedure("#variables('BAtchID')") directly, it will be parsed as is but not as a pipeline variable.
Instead, you need to concatenate the query with pipeline variable using #concat() function in data factory.
The following is a demonstration of how I used query field to execute stored procedure using dynamic content.
You can use the dynamic content below to successfully achieve your requirement (replace stored procedure name and variable name)
#concat('call demo("',variables('value_to_pass'),'")')
The above content will be parsed as call demo("Welcome") which is shown below (\ indicates escape character):
Note: The debug run in the above image failed because I don't have a stored procedure in mysql database.

Executing mysql command using a batch file

I am new to mysql. I've been trying to run a query through windows notepad batch file. The code on the file is:
USE menagerie
SELECT type FROM event
The directory I typed on mysql command line is:
C:/Users/abu/Desktop/ev.txt
The output is: ->
indicating something must be added to complete the command. Please tell me what is missing to complete the code.
You need to use the source command to execute queries from a file.
mysql> source C:/Users/abu/Desktop/ev.txt
Also, the file needs to have ; between queries. So the first line should be
USE menagerie;

Can you pass GETDATE() to a SQL Job that runs SSIS Packages (Set Values)

I haven't been able to find a straight forward answer to this. What I'm trying to accomplish is to execute a SSIS package that requires variables to be set, so I need to pass these variables to SSIS through the SQL Job. I know this is possible through the "Set Values" tab, but I need to pass the current date, so hard-coding a string will not work.
Is it possible to pass GETDATE() or other expressions to the Value field within Set Values? In other words, does the "Value" field get evaluated at runtime?
If this is not possible, what would be a good solution to pass the current day from the SQL job to the corresponding parameter in the SSIS package?
Unfortunately, no. It is not possible assign a method such as GETDATE() to the value property of a datetime variable through the Set Values screen of the SQL Agent Job. The value fields there must be set to discrete values.
I can think of two ways around this.
The first - and easiest option - is editing the package. Open the package with BIDS/SSDT, find that variable, and set that "Evaluate As Expression" property of that variable to True. Then in the properties window of that Variable, click the Expression ellipsis... and set Expression equal to GETDATE(). Save package. When the package runs, that variable will evaluate to GETDATE().
The second method takes a bit more sweat, and has risks, but allows you to dynamically set SSIS package variables. Instead of using SQL Server Job to call a package. Scheduled job which calls an SP. This SP will then execute the SSIS package using xp_cmdShell and the DTEXEC.exe command line tool.
Here is an example. The DTEXEC.EXE command line tool has a /SET argument that basically does the same thing as the Set Values dialog box. But this way its dynamic. Inside the SP you can
DECLARE #MyDate datetime
SET #MyDate = GETDATE()
You just need to get your #MyDate value over to the /SET argument of DTEXEC.
Also, instead of GETDATE() you could also have a parameter that lets you build this date variable on the command line from a combination of substrings of the %DATE% and %TIME% system environmental variables.
set MyDate=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2% %TIME:~0,8%
dtexec /FILE "\"D:\SSIS\Package1.dtsx\"" /SET "\"\Package.Variables[VarDateTime].Value\"";"\"%MyDate%\""
An example of that is over here.
Obviously, option one is easier and less risky. Good luck!
When a job kicks off an SSIS package, the parameters it passes have to be hard-coded in the job.
If you need to pass more context-sensitive values to the package, the best way I've found to do it is to populate a meta-data table in your database, and have the first step in the job be to select the latest row from that table and populate variables from it.

SSIS can't use variables (Flat File > OLE DB Command), Must declare the scalar variable "#"

Apologies, I'm an SSIS noob and I'm struggling with trying to import a flat file and do an OLE DB command WHILE including a variable in the SqlCommand.
You can see my query and the attempt to include an already defined variable. The error is displayed below:
Must declare the scalar variable "#" I understand what the error is saying, but after hours of searching, I cannot figure out how to use variable in the OLE DB Command.
Thanks in advance for any assistance.
Try putting the ssis variable [user::ClientID] into a derived column and add it to the data flow. You should be able to use a ? and assign that value to your query just like any other value in your data flow.