I have an Execute SQL Task which runs a simple query
datatype filename varchar(255) filenumber int id uniqueidentifier
select i.filename , i.filenumber,s.id , 'Files loaded over days' as ErrorMessage from table I inner join tableB s on i.filenumber = s.filenumber where datediff(day,i.filedate,i.adddate)>=5
I have added the resultset as user:ObjServiceID
Now I have used a Foreach ADO Enumerator and in Ado Object Source variable called user::objServiceID
Variable mappings User:ID 0 User::Filenumber 1 User::Filename 2 User::Errormessage 3
and inside the ForEach Loop container I have another Execute Sql task that calls a Stored procedure Parameter Mappings User:: ID GUID 0 -1 User::Filename Varchar 1 -1 User :: Filenumber Numeric 2 -1 User::ErrorMessage Varchar 3 -1
The stored procedure Exec XYZ has variables #filename varchar (255), #filenumber int, #id uniqueidentifier, #Errormessage varchar(2000)
I am constantly getting an error that says "[Execute SQL Task] Error: Executing the query "exec XYZ" failed with the following error: "Procedure or function "XYZ" expects parameter '#ErrorMessage', which was not supplied.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
Even if I try to remove the Errormessage from the parameter and variable mappings it still throws this error. Could someone help with this. Thanks in advance
The m in Error message needs to be upper case in your mapping. It says ErrorMessage was not supplied because you have it as Errormessage.
Related
I am trying to check if an stored proc input is
CREATE DEFINER=`user`#`%` PROCEDURE `driver_journey_ids`(
IN p_driverID VARCHAR(255), # driver ids
IN p_vehicleID VARCHAR(255), # vehicle ids
)
SELECT
pl.eventID
FROM payload AS pl
WHERE
CASE
WHEN p_driverID IS NOT NULL THEN pl._driverID IN (p_driverID)
ELSE TRUE
END
AND CASE
WHEN p_vehicleID IS NOT NULL THEN pl._vehicleID IN (p_vehicleID)
ELSE TRUE
END
CALL driver_journey_ids("123,124,125",null)
The SP is something like this, but the WHEN is causing an issue.
Is there a way to check if an array has a value?
It works if a single value is passed in the call, but not if more than one is passed in the same parameter.
Cheers,
Phil
Using Microsoft SQL Server 2016 (RTM) Standard Edition, I am trying load a JSON into a SQL Server table using a SQL Server Agent Job, and get the following error:
JSON text is not properly formatted. Unexpected character '"' is found at position 508. [SQLSTATE 42000] (Error 13609).
But when I run it as T-SQL it inserts the data with out errors.
DECLARE #return_value int,
#responseText nvarchar(MAX),
#json nvarchar(MAX)
EXEC #return_value = [dbo].[HTTPRequest]
#URI = N'http://flexapi.foresightgps.com/ForesightFlexAPI.ashx',
#methodName = N'post',
#requestBody = N'{"method":"GetTagTempHistory","conncode":"PROVIDER","code":"USERNAME","wsuserid":"USERID" }',
#SoapAction = 'MSXML2.ServerXMLHTTP',
#UserName = N'USERNAME',
#Password = N'PASSWORD',
#responseText = #responseText OUTPUT
--SELECT #responseText as '#responseText';
SELECT #json= VALUE FROM OPENJSON(#responseText) WHERE [key]='ForesightFlexAPI';
INSERT INTO Localizado([TransactionID],[TrueTime],[Temp],[Name],[yLat],[xLong],[Speed],[Ignition],[Location])
SELECT [TransactionID],[TrueTime],[Temp],[Name],[yLat],[xLong],[Speed],[Ignition],[Location]
FROM OPENJSON(#json,'lax $.DATA')
WITH( TransactionID nvarchar(20) '$.TransactionID',
TrueTime NVARCHAR(50) '$.TrueTime',
Temp decimal(9,4) '$.Temp',
Name nvarchar(50) '$.Name',
yLat nvarchar(50) '$.yLat',
xLong nvarchar(50) '$.xLong',
Speed nvarchar(20) '$.Speed',
Ignition nvarchar(20) '$.Ignition',
Location nvarchar(500) 'lax $.Location'
)
The problem is that the JSON string, returned from the API, got truncated when executed from SQL Server Agent Job, but not from SSMS. So the unexpected character will always be something near 512.
Similarly, it'll throw a XML parsing error if the job returns XML instead of a JSON string.
The solution is to SET TEXTSIZE -1, in your SQL Server Agent Job, before executing your stored procedure. The command of your SQL Server Agent Job should be something like this:
SET TEXTSIZE -1
EXECUTE [your stored procedure]
If you are curious about the difference, you may insert your #responseText into a temp table and you'll certainly see a truncated JSON string without SET TEXTSIZE -1 if #responseText has more than 512 characters.
Using SQL Server 2008.
Wanted to output a parameter (#countcase) from a stored procedure called sp256. But when I exec the stored procedure, an error shows up:
Procedure or function 'sp256' expects parameter '#countcase', which was not supplied.
The query was to count the total number cases with contact date later than 1 Nov 2016 and output as a parameter.
The stored procedure:
CREATE PROC sp256
#countcase AS INT OUTPUT
AS
BEGIN
SELECT #countcase = COUNT(DISTINCT case_referenceid)
FROM Cases
WHERE case_contactdatetime > '2016-11-01'
--RETURN
END
The EXEC statement:
DECLARE #reference INT
EXEC #reference = sp256
SELECT #reference AS [List of cases]
PS: the #countcase should output 268 cases in total.
Can someone please help.
Your proc structure sets an output parameter, doesn't return a value. So that you need to provide an output parameter as expected.
EXEC dbo.sp256 #reference output
I have the same code below:
CREATE PROCEDURE TEST1
(#id INT, #name NVARCHAR(30) OUTPUT)
AS
SELECT #name = NAME
FROM TEACHER
WHERE ID = #id;
AND
CREATE PROCEDURE TEST2(#id INT)
AS
DECLARE #name NVARCHAR(30);
SELECT #name = NAME
FROM TEACHER
WHERE ID = #id;
RETURN #name;
The top code is OK, but the second I get an error :
Msg 245, Level 16, State 1, Procedure TEST2, Line 174
Conversion failed when converting the nvarchar value 'Nguyễn Thanh Tùng' to data type int.
Can you help me explain and fix it ??
You cannot return a varchar from a SQL Server stored procedure using RETURN - you can only return integer values.
See the MSDN documentation on "Returning Data Using a Return Code" which clearly states:
A procedure can return an integer value called a return code to indicate the execution status of a procedure.
Typically, such a value is used to either indicate the number of rows affected by your stored procedure, or to indicate an error code.
If you need to return a string, you have to use either an OUTPUT parameter, or return a result set (using a SELECT statement).
on ssis
I am working with ##tmptables
obviosly I am using RetainSameConnection to True
but if I execute my packege this fail when I have a select to this table or other (I have more than 1 ##table)
for example this is a (part of a) query's sql task
THIS DOES NOT FAIL ALWAYS.. but is failing aprox 8 of every 10 execution.
(on production when this fail, this get fail about 8 times continues(or more)) I have seen if I put a Break Point Before to execute this sql task and I copy and paste the code on sql manager and execute the query THIS WORK OK, and if I press play on visual studio(play to continue the process) this work OK)
other times I dont do nothing and this work OK.
declare #tablad nvarchar(max)
set #tablad =?
declare #tipoprom as int
set #tipoprom=?
declare #mexico bit
set #mexico=convert(bit,?)
declare #feccaja datetime
set #feccaja =?
declare #tabladinamica nvarchar(max)
set #tabladinamica=?
if(#mexico =1)
begin
return
end
declare #ordercode as table
(
id int
)
insert into #ordercode
exec('select id from ##'+#tablad+' where tabla=''[order]''')
select
pro=opd.xxx,codbi=o.yyy,cedis=o.zzz,fecha=#feccaja,fechaactual=GETDATE (),aaa=o.bbb
into #tmp
from
...
declare #cadena varchar(max)
set #cadena ='
delete from ##prompro'+#tabladinamica+'
insert into ##prompro'+#tabladinamica+'
select * from #tmp
'
execute(#cadena)
if you need the error , it is.
[Execute SQL Task] Error: Executing the query " my query " failed with the following error: "Excepción de HRESULT: 0x80040E37". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.