Missing parameters in SQL Server stored procedure - sql-server-2008

This SP "dbo.PM_Add_PM_Plates" expects this list of parameters as follow
#PM [T_PM_Add_Plates] READONLY,
#Amount NUMERIC,
#From_Type INT,
#From_Partner VARCHAR,
#From_CashDrawer CashDrawerNumber=NULL,
#To_Type INT,
#To_Partner VARCHAR,
#To_CashDrawer CashDrawerNumber=NULL,
#TransactionName TransactionName,
#MovementType INT,
#CustomerAccount AccountNumber,
#BusinessDate BusinessDate,
#Operator OperatorID--,
but When i trying to execute this SP from my application
the list of parameters passed to SP shown in SQL Server profiler are as follows
#Amount NUMERIC,
#From_Type INT,
#From_Partner VARCHAR,
#From_CashDrawer CashDrawerNumber=NULL,
#To_Type INT,
#To_Partner VARCHAR,
#To_CashDrawer CashDrawerNumber=NULL,
#TransactionName TransactionName,
#MovementType INT,
#CustomerAccount AccountNumber,
#BusinessDate BusinessDate,
#Operator OperatorID--,
The first parameter in SP "#PM [T_PM_Add_Plates] READONLY" is missing
which is a user defined table type.
The application shows no errors and run successfully but data in "#PM [T_PM_Add_Plates]" not inserted in DB.
I want to know if there is any restrictions for using user defined table type in SP or any permissions.
Any help please.
Thanks in advance.

Related

Azure Data Factory - Get SCOPE_IDENTITY value from MYSQL Stored Procedure

I'm using Lookup activity to invoke a MYSQL Stored Procedure. The requirement is to insert a record into a table, get the latest primary key and use that in another activity.
Below is the Stored Procedure
CREATE Procedure usp_LogAudit (
p_pipeline_id int,
p_status varchar(20)
)
begin
Insert into PipelineExecutionLog
(
pipeline_id,
execution_start,
execution_end,
status
)
values
(
p_pipeline_id ,
utc_timestamp(),
null,
p_status
);
SELECT LAST_INSERT_ID() AS SCOPE_IDENTITY;
end;
As, I'm using MYSQL, I don't have the facility to directly import the Stored Procedure along with it' parameters. (Note: For MS-SQL, it's straight forward)
As shown below, I'm using the Query option and invoking the MYSQL Stored Procedure using the 'call'.
Below is the Dynamic Expression
#concat('call usp_LogAudit(',variables('PipelineId'),',','''',variables('PipelineStatus'),'''',')')
The Lookup activity is calling the Stored Procedure successfully at database side. However, in ADF, it's throwing an error.
Not sure how to fix this. Any advice is appreciated.

Select query output in mysql and differes between SP and query execution

Why is my query output different between SP and query execution. I am executing a simple select query to assign some value..
SP:
CREATE DEFINER=`root`#`localhost` PROCEDURE `INS_EXPENSES`(
IN CATNAME varchar(100),
IN SUBCATNAME varchar(100),
IN AMOUNT INT,
IN USERID INT,
IN DESCRIPTIONS varchar(100)
)
BEGIN
SELECT SUBCATNAME;
SELECT * FROM SUBCAT WHERE SUBCATNAME='MISC';
END
THE ABOVE SELECT QUERY RETURNS ALL DATA FROM THE SUBCAT TABLE. WHERE IN SAME QUERY WORKS FINE IF EXECUTED OTHERWISE.
Your procedure has parameter SUBCATNAME and the WHERE-clause is using that value instead of the column with same name when it compares with the "MISC"-string.
You should use a prefix for the procedure parameters so that they would not get mixed up with column names (use parameter names like in_SUBCATNAME or similar)

MySQL Stored Procedure works as plain SQL

I'm trying to write a stored procedure that inserts into one table (A), then queries another table (B), then finally inserts into table (C) the last insert id, along with the result from table B. I have written a stored procedure named VetIdFromCode to do the selecting from table B, which works fine in isolation. When I run the query in isolation, subbing in value for the IN parameters then it runs fine, but when I try and save it as a stored procedure it tells me invalid SQL near 'SET #LIID...'
Many thanks for any help.
CREATE PROCEDURE `NewClientUser`(
IN `uemail` VARCHAR(60),
IN `uphash` CHAR(40),
IN `uvcode` VARCHAR(11))
DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY INVOKER
INSERT INTO users (user_id,user_email,user_hash,user_role)
VALUES (NULL,uemail,uphash,'1');
SET #LIID = LAST_INSERT_ID();
CALL `VetIdFromCode`(uvcode, #VID);
INSERT INTO user_vet_lookup(user_id,vet_id)
VALUES (#LIID,#VID);
You need to start the "code" of the procedure with the key word "BEGIN" and put an "END" at the end. Like:
CREATE PROCEDURE `NewClientUser`(
IN `uemail` VARCHAR(60),
IN `uphash` CHAR(40),
IN `uvcode` VARCHAR(11))
BEGIN
DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY INVOKER
INSERT INTO users (user_id,user_email,user_hash,user_role)
VALUES (NULL,uemail,uphash,'1');
SET #LIID = LAST_INSERT_ID();
CALL `VetIdFromCode`(uvcode, #VID);
INSERT INTO user_vet_lookup(user_id,vet_id)
VALUES (#LIID,#VID);
END
Check out the documentation: http://dev.mysql.com/doc/refman/5.7/en/create-procedure.html

SQL Server could not convert data value

I am trying to import data from SQL Server to mysql using OPENQUERY with a linked server.
I have imported couple of tables but I am having an issue with a table that has a long varchar field.
everytime i run this query I get the following
Msg 7344, Level 16, State 1, Line 2
The OLE DB provider "MSDASQL" for linked server "Serv1" could not INSERT INTO table "[MSDASQL]" because of column "Notes". Could not convert the data value due to reasons other than sign mismatch or overflow.
the column Notes is of the type varchar(8000) in SQL servr and also varchar(8000) in MySQL.
What is the issue? why it is giving me this error? not I have tried to case Notes to varchar(8000) first but that did not work.
INSERT OPENQUERY (Serv1, 'SELECT
id,
i3_identity,
mid,
Notes,
Comments,
result_code,
Disposition,
completed_on,
calltype
FROM finaltesting.activities')
SELECT
CAST(ID AS int) AS id,
CAST(identity AS int) AS identity,
CAST(merchantAccount AS varchar(255)) AS mid,
Notes,
CAST(Comments AS varchar(8000)) AS Comments,
CAST(FinishCode AS varchar(255)) AS result_code,
CAST(Disposition AS varchar(255)) AS Disposition,
CAST(callDate AS datetime) AS completed_on,
CAST(CallType AS varchar(255)) AS calltype
FROM activities
Could not convert the data value due to reasons other than sign mismatch or overflow.
I was able to solve this problem by changes the column type in MySQL from varchar(8000) to Text. I am using MySQL 5.6.12. It is probably column type issue when converting form SQL Server to MySQL Server.
Thanks

LINQ Issue, Dragging stored procedure returns int rather than Result

This is the stored procedure.
ALTER PROCEDURE [dbo].[UserSearch]
(
)
AS
SET NOCOUNT ON
DECLARE #temp TABLE
(
Id INT,
UserName INT,
StatusId INT
)
INSERT INTO #temp
SELECT userId, userName, statusId FROM [User]
SELECT UserId,
COUNT(ISNULL(StatusId, 0)) AS UserCount,
StatusTypeName
FROM #temp
GROUP BY StatusTypeId, StatusTypeName
When i run this then it works fine. Yesterday when i drag this stored procedure in the method pane in dbml file then it doesn't create UserSearchResult class and it returns int rather than ISingleResult. But today in the morning i have dragged it again and now it has created the class and also returns ISingleResult, which is correct. But i am too much confuse with the linq behavior why this occur? It waste my time too much.
When that happens to me depends on the access level that the connection has on the Stored Procedure. If you don't have execution access it will return an integer because a Stored Procedure always return an integer.
Also it can be related to not having the SELECT statement(s) at the end of your stored procedure, because it uses those statements to figure out the result types.
Hope this helps