How to invoke stored procs with parameter using T-SQL scripting? - edge.js

We are using edge-sql to execute T-SQL scripts and also stored procedures via C#. I noticed recently that stored proc support has been added and I'm trying to execute would would be:
exec dbo.sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx';
in SQL Server Management Studio, using edge-sql 0.1.2.
I've played around with several variations, but I get one of 2 error messages. Either cannot find stored procedure '' or "cannot find stored procedure 'sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx'" The stored proc executes just fine in edge.sql when invoked via C# method.
I did some additional experimentation and found I can execute a stored proc with no parameters: exec dbo.sgVersionGet, but any stored procs with parameters return errors.
So what am I doing wrong? And how could I invoke with parameter values that aren't hard-coded, as above? Both SQL Server and edge use the # character for parsing params.
Any help appreciated ...
-BillyB

In SQL Server when you are referring to a database object without the object full path ([database.schema].object), SQL Server will try to locate the object using the Default/Initial Catalog value which points to the default database if that was not specified within the connection string then chances are that when you try running your statement SQL Server won't be able to find the object throwing the "Cannot find XX" error, You should either specify an initial catalog on your connection string or execute your procedures using the full path, database.schema.procedure E.g. mydatabase.dbo.sp_customerCleanUp. On the other hand there is an internal procedure sp_executesql that you can use to run your procedures without having to hard code the parameters, all you need to do is build a string concatenating the hard coded part of the string (the procedure name) and whatever number of variables you are passing as parameters, see example ( https://technet.microsoft.com/en-us/library/ms175170%28v=sql.105%29.aspx )

The variables are assumed when calling a stored procedure with edge-sql. Any parameter you would preface with an '#' symbol will need to have the same name within the stored procedure.

Related

SQL Transformation in Informatica for Google Bigquery

I have a SQL Script with multiple drop & create DDL(Create tables As Select *), I want to run them at one go. I am quite new to informatica powercenter, can some one provide the process of using SQL transformation for BigQuery in informatica.
Sample Query:-
drop table if exists sellout.account_table;
CREATE TABLE sellout.account_table
AS
SELECT * FROM
sellout.account_src
WHERE
UPPER(account_name) IN ('RANDOM');
Similar to the above queries i have around 24 SQL's in a script.
I want to run them at once and later make them as part of informatica job.
If the "PowerExchange Google BigQuery" server and client are installed and after executing the infasetup.bat(sh) validateandregisterallfeatures, the mappings would be opened/exported successfully.
Here are some FAQs that might be handy for you:
Q: Why are the output fields in SQL Transformation not seen?
​A: Stored Procedure selected in the SQL Transformation must have output parameters declared. Else it would not have output fields other than default Return Code column.
​​
Q: A set of columns are displayed as result while running the Stored Procedure, however, you still do not see the same columns as output in SQL Transformation. Why?
A: Columns seen in the output might not be defined/declared as output parameters in the Stored Procedure. Procedure might have 'SELECT * FROM' like statement, which retrieves the data when the procedure is run from DB UI and a similar result could be seen when the procedure is run programmatically.
However, to call the same procedure from SQL Transformation, explicitly declared output parameters should be present as the transformation imports the metadata of the proc when selected. Unless you declare the output parameters explicitly in the procedure, it cannot be seen as output in the transformation.
​Q: Is it necessary to have input/output parameters in Stored Procedure to call it from SQL Transformation?
A: Yes, it is necessary to have input/output parameters in Stored Procedure if it is not having default ones. As these parameters appear as input/output fields in SQL transformation, without these Mapping becomes invalid.
Q: I have SELECT statement in the procedure, does the SQL transformation can push this to next transforamtion?
A: Approprioate output parameters are required for this to work.

The SQL command requires a parameter named "#SessionID", which is not found in the parameter mapping

I'm trying to execute a stored procedure via SSIS
Error: 0xC0207014 at PO Header, OLE DB Source [59]: The SQL command
requires a parameter named "#SessionID", which is not found in the
parameter mapping.
But as you can see below, the variables are populated, I have mapped the parameters.
So what's going on?
MS SQL 2014
MS Visual Studio 2015
Based on the screenshots, you have mapped variables to parameters. Then just try to delete and recreate the OLE DB Source.
The SQL command requires a parameter, which is not found in the parameter mapping
If it still throwing an error, then use expressions instead of parameters. You can refer to the following link for more information:
Unable to pass a variable value to a stored procedure in ssis
I was having the same issue and even having Visual Studio crash on me. I found that rather than using parameter index of 0,1, 2... I used named parameters in my OLEDB connect and this resolved my error. You must include the # in the parameter name and they must match your sql stored procedure parameter names.
For example instead of [0] and [1] name parameters #StartDate and #EndDate

SQLException 00604 & 01003 while calling stored procedure from hibernate named query

We are calling a stored procedure ( which calls another inside it) from hibernate.
Query query = session.getNamedQuery("query_name");
query.setParameter('param', 'value');
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List returnList = query.list();
The stored procedure is independently running good when we run in SQL developer. But we run this through application it is giving following error.
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-01003: no statement parsed
Things we tried :
calling a simple stored procedure from hibernate - working well.
creating the test case to test the method in which the stored
procedure (which throws error) is being called - working well.
Our question is , why the same query is running good in test case, and not while running thorugh application ?
Any ideas?
Update
It was my fault, i was passing the arguments in-correctly. Just swapped the first tow arguments. To anybody facing this issue, please check your argument ordering in the named query.
Thanks.
It was my fault, i was passing the arguments in-correctly. Just swapped the first tow arguments. To anybody facing this issue, please check your argument ordering in the named query.

SQL Server Report Parameter

I'm create a SQL Server Report using Business Intelligence tool (visual studio shell 2005) for SQL Server 2008.
I'm calling a stored procedure with 2 parameters. I've tried - Report-> Report Parameter, Added two parameters name them Days and Count.
In the Data panel "command type:text"
exec dbo.DataReport #Days, #Count
error: Must delcare the scalar variable "#Days"
Does anyone know how do get this too work.
Try changing the command type to Stored Procedure, i'm sure its worked for me in the past
If changing the command type to Stored Procedure like was suggested didn't work, try opening the Dataset dialog box and going to "Parameters" tab. Make sure that both parameters ("#Days" and "#Count") are in the list and that each one has a value.

calling a sql stored procedure using the rows() method in grails?

I am working in a previously existing grails project that has some search functionality built into it. It has created a new Sql object using my SQL Server datasource, and it seems like it is attempting to call a stored procedure like so:
def qResults = sql.rows(spCall)
where spCall is a String and looks like this:
EmployeeQueryClient 'SomeClient', 1,1,0
Where "EmployeeQueryClient is the name of the stored procedure, and the other things are the parameters.
I can't find any documentation supporting this kind of call - is this correct? How would I really do this if it is not?
In the code shown above sql is an instance of groovy.sql.Sql. This provides a rows(String sql) method that can be used to execute SQL and returns the result.
Generally speaking, I think this rows method is a bad choice if you want to call a stored proc, because you have to concatenate the name of the proc and all the args into a single string, which is a bad idea from the point of view of both type safety and readability.
Instead use one of the overload call methods provided by the same class, which are specifically intended for invoking stored procedures. For example, if you just want to invoke the procedure (ignoring any results it returns) use:
sql.call("{call EmployeeQueryClient(?, ?, ?, ?)}", ['SomeClient', 1, 1, 0])
The syntax used here for calling a stored proc,
{call PROC_NAME(PROC_ARGS)}
will work for MySql. If you're not using MySql you'll need to replace this with whatever is used by your RDBMS to invoke a stored proc.
Overloaded versions of the call method enable you to handle any results returned and/or ouput parameters of the stored proc.