Mapping Output Parameters in SSIS OLE DB Source Editor - sql

How can i map output parameter in OLEDB Soruce SSIS(BIDS 2008).In (BIDS 2012) we can specify the query parameter as input and output.
SET FMTONLY OFF;
EXEC [dbo].[ProcessPingErrorAlert_KeyValue]
#AlterId = ?,
#Hour = ?,
#Day = ?,
#TraceId = ?,
#IsAlert = ? OUTPUT
Please see below two picutres.
SSIS Package In BIDS 2008
SSIS Package in BIDS 2012

The SQL statement should be:
EXEC ? = [dbo].[ProcessPingErrorAlert_KeyValue] ?, ?, ?, ?, ? OUTPUT .
Then edit SQL task and choose, in Parameter Mapping, #IsAlert as Output (check pic just for reference, variables are different). The first question mark is just for the return value (you have to declare that variable amd in Parameter Mapping).
Please respect the order you have your question marks and its correspondence by 0, 1, 2, ...
For further information you can try to read this:
https://sqlserverrider.wordpress.com/2014/08/31/execute-stored-procedure-with-input-and-output-parameters-and-return-status-in-ssis/

you need in Mapping to do the following:
Parameters: Put the name of the parameter like you named at the stored procedure.
Variables: Put the name of the variable you want to store the parameter after the execution.
Param Direcction: You have to select Output.
Before the Mapping, you will need to create a variable.

Related

Python - Defining output of query to variables

I am trying to call the output of SQL query to variables as below:
cur = conn.cursor()
cur.execute("""select store_name,DATE_TRUNC('month',bill_date)as month,count(*) from sales""")
monthly_report = dwh_cur.fetchall()
The output of this file is as below:
store_name,month,count
store_a,jan,100
store_a,feb,200
store_a,mar,230
I am trying to pass months to a variable (var1) and count to another variable (var2)
Could anyone advice how could I define this accordingly. Thanks

OLE DB Source not accepting variable as parameter

EXEC dbo.event #first_param = 'smth', #second_param = 'IS', #date_param = '2016-10-31 09:58:24.690', #databaseparam = 'dtp'
I have a variable databaseval with the scope of the whole package and Data Type = String and its value is dtp
However when map the variable to OLE DB Source editor I get 'Invalid object name .smth.mytable'. Does this mean that the dtp parameter is not passet or what?
This is not ok
EXEC dbo.event #first_param = 'smth', #second_param = 'IS', #date_param = '2016-10-31 09:58:24.690', #databaseparam = ?
Thanks for helping
In the parameters I put #databaseparam and in the variables
User::databaseval
Don't use the parameter name in the parameter mapping. Instead, use the index of its position in the query.
For example, if it's the only mapped parameter in the query, then use 0.

Perl DBI - binding a list

How do I bind a variable to a SQL set for an IN query in Perl DBI?
Example:
my #nature = ('TYPE1','TYPE2'); # This is normally populated from elsewhere
my $qh = $dbh->prepare(
"SELECT count(ref_no) FROM fm_fault WHERE nature IN ?"
) || die("Failed to prepare query: $DBI::errstr");
# Using the array here only takes the first entry in this example, using a array ref gives no result
# bind_param and named bind variables gives similar results
$qh->execute(#nature) || die("Failed to execute query: $DBI::errstr");
print $qh->fetchrow_array();
The result for the code as above results in only the count for TYPE1, while the required output is the sum of the count for TYPE1 and TYPE2. Replacing the bind entry with a reference to #nature (\#nature), results in 0 results.
The main use-case for this is to allow a user to check multiple options using something like a checkbox group and it is to return all the results. A work-around is to construct a string to insert into the query - it works, however it needs a whole lot of filtering to avoid SQL injection issues and it is ugly...
In my case, the database is Oracle, ideally I want a generic solution that isn't affected by the database.
There should be as many ? placeholders as there is elements in #nature, ie. in (?,?,..)
my #nature = ('TYPE1','TYPE2');
my $pholders = join ",", ("?") x #nature;
my $qh = $dbh->prepare(
"SELECT count(ref_no) FROM fm_fault WHERE nature IN ($pholders)"
) or die("Failed to prepare query: $DBI::errstr");

Interpolation and single quoted strings in SQL query

I just started of with databases with SQLite3 and Ruby. I have run into a problem with my ruby code here.
I want to create a code where the user adds another record to the database. Now here is my problem.
User sawa found the solution of my first problem. Thank you!
NEW PROBLEM*
puts "Enter name for the new user"
x = gets.chomp
puts "Enter the type of the user"
y = gets.chomp
$db.execute('insert into customers(id,name,type) values (11,"#{x}","#{y}")')
When I run this code and input the x any y value it will return in my database #{x} and #{y} and not the values I created.
You're actually going about this all wrong. You shouldn't be using string interpolation for SQL at all, you should be using placeholders and bound variables. The README even includes an example:
# Execute a few inserts
{
"one" => 1,
"two" => 2,
}.each do |pair|
db.execute "insert into numbers values ( ?, ? )", pair
end
and the fine manual even mentions bound variables in the second sentence:
- (Object) execute(sql, bind_vars = [], *args, &block)
Executes the given SQL statement. If additional parameters are given, they are treated as bind variables, and are bound to the placeholders in the query.
So you should be saying this:
$db.execute('insert into customers (id, name, type) values (?, ?, ?)', 11, x, y)
or this:
$db.execute('insert into customers (id, name, type) values (?, ?, ?)', [11, x, y])
As is warned, don't use single quotes. Use double quotes. Expressions in single quotes are not ignored. They are evaluated literally.

Using PDO for an insert and the_geom

I'm switching my code to PDO for increased security. My insert works until I add a special column that create spatial data. See below for the standard insert that works, and 2nd below for what is not working.
$sql = "INSERT INTO sites_tbl (sitename, the_geom) VALUES ('$_POST[sitename]', st_geomfromtext('POINT($geomstring)',27700))";
The geomstring = a number formatted 000000 000000
Using PDO the same insert looks something like (below) this works if I just want to insert the sitename, but not when I do the_geom. The value 325123 215432 will eventually be a variable, but for now I'm testing list this.
$stmt5 = $conn ->prepare(
"INSERT INTO sites_tbl (sitename, river_id, group_id, accepted_site, the_geom, bmwp_threshold) VALUES (?, ?, ?, ?, ?, ?)");
$stmt5->bindParam(1, $sitename);
$stmt5->bindParam(2, $river_id);
$stmt5->bindParam(3, $group_id);
$stmt5->bindParam(4, $accepted_site);
$stmt5->bindParam(5, $geomstring3);
$stmt5->bindParam(6, $bmwp_threshold);
$geomstring2 = "'POINT(635230 352120)'";
$geomstring3 = st_geomfromtext($geomstring2, 27700);
you cannot
bind
an arbitrary
SQL part
using
prepared
statement
but string
or numeric
literal
only.
$geomstring4 = "'POINT(325123 215432)'";
$stmt5 = $conn ->prepare(
"INSERT INTO sites_tbl (sitename, the_geom) VALUES (?, st_geomfromtext(?,27700)))");
$stmt5->bindParam(1, $sitename);
$stmt5->bindParam(2, $geomstring4);