How to replace Database name in SQL file in Gitlab Pipeline? - sql

I am deploying database through gitlab. I have a case where database name should be passed as variable and replaced in the sql file but it's not working.
e.g,
the script has {{ db_name}}.schema.table
I have set db_name as variable in gitlab-ci.yml but this variable doesn't get picked up and pipeline fails.
variables:
db_name: xxxx
Is there a way to set database name as variable which will replace the dataabse name and runs the pipeline

Related

Referencing Azure DevOps Variable Group values in a YAML Pipeline

I have created three Variable Groups in Azure DevOps which comprise of three variables:
WebApp-DEV
WebApp-QA
WebApp-Prod
Each variable group has a variable named environment whose value is appropriately named to correspond with the environment.
What I'd like to do now is reference each environment variable in my Azure Pipeline yaml file. The screenshot below depicts how I'm currently referencing the variable group WebApp-DEV in the pipeline DEV stage.
How do I however call or reference the environment values for each variable group, as per the above depiction for WebApp-DEV? In other words, what is the syntax required to reference the value of my variable from a variable group?
When you reference variable group all variables from variable group are available in the scope which you reference variable group. So ig you have WebApp-Dev referenced on job level you can use variables from this group in this job. And the syntax, well if you have env variable defined in variable group it should be $(env) and just it.
stages:
- stage: DEV
jobs:
- job: DEV
variables:
- group: WebApp-Dev
steps:
- script: echo '$(env)' #env comes from WebApp-Dev variable group

SSIS Variables Not Updating When Execute Package on Server

I have created a package that does the following:
ExecuteSQLTask: queries db table and sets package variables from data returned
DataFlowTask starts
OleDBSource: uses package variables as parameters to call stored procedure
FlatFileDestination: uses package variables to save a tab delimited file in the correct location and filename
SendEmailTask: uses package variables to email the file as attachment to recipient
I have the following vars:
FileName
sp_Param1
sp_param2
emailRecipient
SMTPServer
At design time, each var has dummy values. When I run the package in VS, it works perfectly. I can update the values in the db table and each execution picks up the new values and works.
The problem begins when I deploy the package to the database and execute it. It appears to not be setting the variables from the db table any longer and it uses the dummy data that I used during design time. What is going on?

changing database name in sql server script

I created a schema script for an sql server database called test.
I want to execute this script in the same server where the test database is found, but for sure with different name, suppose test2.
when I opened the scripts, it starts by CREATE DATABASE [test] and the name test is used many times in the script.
so how to safely change database name in the script without affecting the original database?
Note: changing name by just replacing it's name is not a solution because it's name is a part of many procedures and functions
No need to use database name in each and every query. Just use
USE [Database_Name]
in the above of the script file, then it will consider the database for the entire script until you specify another database name inside the script.
Eg:-
USE My_Database_1
Script_1
Script_2
.
.
Script_n
--Another Database if required
USE My_Database_2
Script_1
Script_2
.
.
Script_n

pass a column value to ssis variable

I have a job that I want to run that passes a variable to an ssis package. The variable is a filename but the filename changes daily. I have an access front end that the user enters the filename into. The access program runs a stored procedure which writes the filename to a temp table and then runs the job. I would like the job to query that table for the filename and pass it along to my package variable.
I can get the job to work using a static filename. On the set values tab I used the property path \Package.Variables[User::FileName] and the value \myserver......\filename.txt. But I don't know how to replace that filename with the results of the query
Thanks in advance.
Scott
I may have spoke too soon. The data source saved in my job step was still an value in my package. I had removed the value but didn't re-import the package to SQL. Now that I did that it is not importing anything at all.
I ended up creating an Execute SQL Task in my package that assigns the value in the temp table to my package variable.

Passing parameters to oracle script

This is my scenario.
I have Test1.sql, Test2.sql and Test3.sql files with create, drop, insert, etc statements. The number of files could increase in the future.
I wanted to run all of them in a single script so I created a master script Master.sql, which has the below
##Test1.sql
##Test2.sql
##Test3.sql
I run it as #"Path to the script\master.sql" using SQL plus command prompt on my windows and if I wanted to run it through SQL developer, I just open the master.sql file and run it. So far so good…
Now, I have to run the master.sql in various environments with different user and schema names but the user and schema names are hard coded in the scripts. I want to be able to replace all the occurrences of the hard coded names with parameters and pass them just once on Master script execution. Both from the command prompt and using SQL developer. How do I do it? Please advice.
Have a look at the documentation of the SQL*PLUS User Guide and Reference.
From the manual:
You can bypass the prompts for values associated with substitution
variables by passing values to parameters in a script through the
START command. You do this by placing an ampersand (&) followed by a
numeral in the script in place of a substitution variable. Each time
you run this script, START replaces each &1 in the file with the first
value (called an argument) after START filename, then replaces each &2
with the second value, and so forth. For example, you could include
the following commands in a script called MYFILE:
SELECT * FROM EMP_DETAILS_VIEW
WHERE JOB_ID='&1'
AND SALARY='&2';
In the following START command, SQL*Plus would substitute PU_CLERK for
&1 and 3100 for &2 in the script MYFILE:
START MYFILE PU_CLERK 3100
When you use arguments with the START command, SQL*Plus DEFINEs each
parameter in the script with the value of the appropriate argument.