Multiple Select statements in EXECUTE SQL TASK in SSIS
Can we write multiple select statements in execute sql task(SSIS).
If possible how to assign them to variables in result statement
Hi ,
You can use below steps to set result set to variable.
1.In the Execute SQL Task Editor dialog box, on the General page, select the Single row, Full result set, or XML result set type(According to your result set).
2.Click Result Set.
3.To add a result set mapping, click Add.
4.From the Variables Name list, select a variable or create a new variable.
What is multiple selection ? May be below can be used in your scenario !
http://stackoverflow.com/questions/17698908/how-to-set-multiple-ssis-variables-in-sql-task
What you want to achieve ?
Thanks
Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com
Similar Messages
-
Question:
There is a scenario that users want to send multiple rows returned by Execute SQL Task as Email content to send to someone. With Execute SQL Task, the Full result set is used when the query returns multiple rows, it must map to a variable of the Object data
type, then the return result is a rowset object, so we cannot directly send the result variable as Email content. Is there a way that we can extract the table row values that are stored in the Object variable as Email content to send to someone?
Answer:
To achieve this requirement, we can use a Foreach Loop container to extract the table row values that are stored in the Object variable into package variables, then use a Script Task to write the data stored in packages variables to a variable, and then set
the variable as MessageSource in the Send Mail Task.
Add four variables in the package as below:
Double-click the Execute SQL Task to open the Execute SQL Task Editor, then change the ResultSet property to “Full result set”. Assuming that the SQL Statement like below:
SELECT Category, CntRecords
FROM [table_name]
In the Result Set pane, add a result like below (please note that we must use 0 as the result set name when the result set type is Full result set):
Drag a Foreach Loop Container connects to the Execute SQL Task.
Double-click the Foreach Loop Container to open the Foreach Loop Editor, in the Collection tab, change the Enumerator to Foreach ADO Enumerator, then select User:result as ADO object source variable.
Click the Variable Mappings pane, add two Variables as below:
Drag a Script Task within the Foreach Loop Container.
The C# code that can be used only in SSIS 2008 and above in Script Task as below:
public void Main()
// TODO: Add your code here
Variables varCollection = null;
string message = string.Empty;
Dts.VariableDispenser.LockForWrite("User::Message");
Dts.VariableDispenser.LockForWrite("User::Category");
Dts.VariableDispenser.LockForWrite("User::CntRecords");
Dts.VariableDispenser.GetVariables(ref varCollection);
//Format the query result with tab delimiters
message = string.Format("{0}\t{1}\n",
varCollection["User::Category"].Value,
varCollection["User::CntRecords"].Value
varCollection["User::Message"].Value = varCollection["User::Message"].Value + message;
Dts.TaskResult = (int)ScriptResults.Success;
The VB code that can be used only in SSIS 2005 and above in Script Task as below, please note that in SSIS 2005, we should
change PrecompileScriptIntoBinaryCode property to False and Run64BitRuntime property to False
Public Sub Main()
' Add your code here
Dim varCollection As Variables = Nothing
Dim message As String = String.Empty
Dts.VariableDispenser.LockForWrite("User::Message")
Dts.VariableDispenser.LockForWrite("User::Category")
Dts.VariableDispenser.LockForWrite("User::CntRecords")
Dts.VariableDispenser.GetVariables(varCollection)
'Format the query result with tab delimiters
message = String.Format("{0}" & vbTab & "{1}" & vbLf, varCollection("User::Category").Value, varCollection("User::CntRecords").Value)
varCollection("User::Message").Value = DirectCast(varCollection("User::Message").Value,String) + message
Dts.TaskResult = ScriptResults.Success
End Sub
Drag Send Mail Task to Control Flow pane and connect it to Foreach Loop Container.
Double-click the Send Mail Task to specify the appropriate settings, then in the Expressions tab, use the Message variable as the MessageSource Property as below:
The final design surface like below:
References:
Result Sets in the Execute SQL Task
Applies to:
Integration Services 2005
Integration Services 2008
Integration Services 2008 R2
Integration Services 2012
Integration Services 2014
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thanks,
Is this a supported scenario, or does it use unsupported features?
For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
in a supported way?
Thanks! Josh -
Customized Execute SQL Task in SSIS
Hi,
I,m using Execute SQL Task in SSIS Package with these configuration ..
But, If SQL Statement doesn't report any record mean Query is not returning any data then this Task will be failed.
How can I assure that If there is no record is returning in query that " Execute SQL Task " should bot be executed .
Also I If I can do the same thing through other methods in SSIS, Pls response .
-AshishHi Ashish,
The Execute SQL Task failed because you had set the ResultSet to “Single row”, however, the SQLStatement didn’t return any records. If you don’t want to execute this task when the query doesn’t return any records, you can use the following method:
Create a String type variable RowCnt, add another Execute SQL Task prior to this task.
In the new Execute SQL Task, input the SQLStatement as “Select Count(*) From Table”, set the ResultSet to “Single row”, and map the result set 0 to the variable RowCnt.
Join the two tasks (green line), and edit the Precedence Constraint (Green line), and set the expression to “(DT_I4)@[User::RowCnt]>0”.
Regards,
Mike Yin
TechNet Community Support -
Execute SQl Task Error SSIS Package
Hi all,
I`m using for each loop container in my package to grab the file name from the source path. I have created 2 vairables
FilePath and SourceFolder
I`m using execute sql task inside the container and this is my query
Insert into [dbo].[DCA_FF_TEST] (File_Name,File_Date) SELECT File_name = ?,
File_Date = GetDate()
Please not the Table I am trying to insert has more columns but at this stage I dont need them.
When i execute the task I get an error
[Execute SQL Task] Error: Executing the query "
INSERT INTO [dbo].[DCA_FF_TEST] ([File_Name],[F..." failed with the following error: "The statement has been terminated.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters
not set correctly, or connection not established correctly.
Can someone point me in the right direction? Am I missing anything?
Resultset property Set to None
Parameter Mapping: Variablename: FilePath , Direction: Input, datatype : Varchar, Parametername: 0, ParameterSize: 100.
I`ve checked the connection as well it works.
FMDid you try
Insert into [dbo].[DCA_FF_TEST] (File_Name,File_Date)
SELECT ?, GetDate()
Or
Insert into [dbo].[DCA_FF_TEST] (File_Name,File_Date) VALUES (?, GetDate())
A Fan of SSIS, SSRS and SSAS -
Multiple select statements in PL/SQL
Hi All
I am new to PL/SQL and my experience is in writing TSQL. There we can write a SQL statement like this to return 3 result set
SELECT empname FROM Employee
SELECT authname FROM Author
SELECT athname FROM sport
how can we write the same 3 statements in PL/SQL and attain the 3 resultsets.
I tried to implement the same using PL/SQL anonymous blocks. But it didn't worked.
DECLARE
P_RECORDSET OUT SYS_REFCURSOR
BEGIN
OPEN P_RECORDSET FOR
SELECT empname FROM Employee;
SELECT authname FROM Author;
SELECT athname FROM sport;
END;
can anybody show how it can be done.
Thanks in advance
George
Edited by: user6290570 on Sep 16, 2009 11:23 PMgeorge2009 wrote:
No i just want to select 3 result sets from 3 select statements, so that it is helpful to compare the resultsets. Compare? How? This is done using the SQL language. Not PL/SQL. Not Java. Not VB. Not anything else.
You would use these other language for flow control and certain forms of conditional logic - but the actual comparison of data sets is done in SQL.
Of course, that is if you do want to do it the most optimal way, that will perform well, and scale well.
SQL is not an I/O API layer - to be used to read() a record and write() a record as if the RDBMS is an ISAM file. That form of row-by-row and slow-by-slow processing dates back to the 80's when we used Cobol.. (or at least for those old farts like me that can actually remember coding in Cobol in the 80's ;-) ).
You want to design and code database applications that are fast, robust, and can scale? Then learn how to use SQL correctly. -
How do I create an Event Handler for an Execute SQL Task in SSIS if its result set is empty
So the precedence on my entire package executing is based on my first SELECT of my Table and an updatable column. If that SELECT results in an empty result set, how do I create an Event Handler to handle an empty result set?
A Newbie to SSIS.
I appreciate your review and am hopeful for a reply.
PSULionRPDepends upon what you want to do in the eventhandler. this is what you can do
Store the result set from the Select to a user variable.
Pass this user variable to a Script task.
In the Script task do whatever you want to do including failing the package this can be done by failing the script task, which in turns fails the package. something like
Dts.TaskResult = Dts.Results.Failure
Abhinav http://bishtabhinav.wordpress.com/ -
I always get the count as 0 for the variable. I am not sure what I am doing wrong. Please let me know if any of you know the fix.
ThanksHere is the query I used now. Still same result
SELECT (select count(*) from usr_all_mbrs where PREMIER_YN = 'Y') AS count1
SELECT
(select
count(*)
from usr_all_mbrs
where PREMIER_YN
=
'Y')
AS count1 -
Same parameter multiple times in Execute SQL Task
Hi all,
i have a fairly long parametrized query that needs to be run within an Execute SQL task. It has only 2 unique parameters, but these need to be used multiple within that query. The connection is OLEDB.
ill simplify my requirement by making up an arbitrary T-SQL "where" clause that will illustrate what i need:
where
x = @param1
and y = @param1
and z > @param2
and w > @param2
moving this into an SSIS execute SQL task will require the following:
where
x = ?
and y = ?
and z > ?
and w > ?
I know i need to specify 4 parameters and remap the same variables multiple times.. like so:
User:aram1 -> 0
User:aram1 -> 1
User:aram2 -> 2
User:aram2 -> 3
isnt there a better way? i ask this because in my real task i have 2 params, each is reused 4 and 5 times respectively and it seems stupid to repeat params like this.@ _proffy_
you can pass the same variable or value as parameter multiple times sql task.
follow the steps below.
1) type the sql query with parameters in SQL statement tab of sql task editor
2. in the parameter mapping, select the variables.
you can select the same variables more than once.
give the parameter name as 0,1,2,3..... based on variables you require.
do not forget to chooose the appropriate Datatype.
ex:
select * from table1
where a= ?
and b=?
and c= ?
parameters:
Var name param Name
user::Var1 0
user::Var1 1
user::Var2 2
so the value becomes a=var1, b= var1 and c= var2 -
Executing a stored procedure containing multiple Select statements
Post Author: Beverly
CA Forum: General
I am using Crystal 10.0 against a MS SQL 2000 server.
I am trying to create a report based on a stored procedure that contains multiple select statements. The sp requires a single parameter (Claim number) and contains 17 Select statements that produce results.
I am able to use the Add command and execute the sp with the parameter, but I am only getting the results of the first select statement in the sp back in my data set. Is there a way to have the data from each Select statement returned to my report?
I have used Crystal for a while, but pretty much for straight-forward reporting. I am familiar with the basics of SQL.
I would appreciate any help anyone can offer.
Thanks.Post Author: BISoftware
CA Forum: General
I believe Crystal Reports can only handle one recordset at a time, which means it can only handle a single select statement. The only way I can see around this would be to break up your stored procedure into multiple stored procedures, so that each only contains a single select statement. Then, use subreports to report on each individual sp. Hope this helps. - Davewww.BusinessSoftwareResource.com -
Passing the same input parameter twise in execute sql task
Hi All, I want to insert some values to 3 different tables in sql server. Execute sql task is used to populate three tables. Here is the sql statement.
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT ?, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT ?, COL2, COL3 FROM TABLE_B
Input parameter is mapped as follows :
Variable name : User::EffectiveDate
Direction : Input Data Type :
Date Parameter name :0
Parameter size :-1
User::EffectiveDate is datetime variable.
When the package is executed, it throws an error.
[Execute SQL Task] Error: Executing the query " " failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems
with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. I am not sure what I am doing wrong here. If anyone could point me to the right direction, I really appreciate.
Thanks
shamenTo expand on the other answers.
Your SQL command
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT ?, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT ?, COL2, COL3 FROM TABLE_B
It using 3 input variables. I assume you didn't pass 3 variables and you want @DT to be column 1 in each. In that case you would use:
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT @Dt, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT @Dt, COL2, COL3 FROM TABLE_B -
Execute SQL task for Email ToLine using COALESCE and two variables
Hello...
I am converting an old DTS package to SSIS. The old package consist of mostly ActiveX Script so I am breaking it down into steps. Basically... I am retreving a set of records that need to be sent via email to multiple people. In my package to create
my ToLine for the Send Mail Task I am using several steps. Frist I am using:
SELECT CASE
WHEN EXISTS ( SELECT users.User_EmailAddress
FROM dbo.Errors INNER JOIN
dbo.Users ON users.user_id = Errors.MonitorAuditor_User_Id
WHERE ([Audit_Id] = ?) AND ([ErrorCode_Id] = ?) ) THEN
1
ELSE
0
END AS ValidEventID
I use this to see if there is any records to create my email string. This works fine. After this I have a Script Task that splits my pipe in two. When no records exist (User::ValidEventID == 0) I am loging that event to a log. When records do exist
I am using another Execute SQL task to create the actual ToLine:
Declare @combinedString VARCHAR(max)
SELECT @combinedString = COALESCE(@combinedString + ', ', '') + Users.User_EmailAddress
FROM dbo.Errors INNER JOIN
dbo.Users ON users.user_id = Errors.MonitorAuditor_User_Id
WHERE ([Audit_Id] = ?) AND ([ErrorCode_Id] = ?)
SELECT convert(varchar(4000),@combinedString) as StringValue
I have my resultSet set to Single Row. I have two variables coming if for the Audit_Id and ErrorCode_Id. My Result Set is set to a Variable: User::EmailAddressString.
Next it goes through a foreach loop to map to the ToLine email variable that I created named User:User_EmailAddress.
Then I am using that in my Send Email Task.
It all works fine when I hard code my variables into the COALESCE statement but as soon as I replace that with the ? that SSIS requires for variables I am getting the following error:
[Execute SQL Task] Error: Executing the query "Declare @combinedString VARCHAR(max)
SELECT ..." failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established correctly.
I have tried changing my resultset property, I have checked my paramenters and my connection. I don't understand why it works fine when I have my varaiables hard coded but not when I change them to the ?.
Thanks in advance for you help in this matter.
Reach for the unknown!Katherine... that did not work.
What I ended up doing was taking out the forloop all together. In my Execute SQL Task I changed the result set from single row to XML. I took out the COALESCE statement and just went for something more basic:
select users.User_EmailAddress + ';' as User_EmailAddress from Errors inner join users on users.user_id = Errors.MonitorAuditor_User_Id WHERE ([Audit_Id] = ? AND [ErrorCode_Id] = ?)
Currently I am just logging the string to a text file so I can see the results. In my text file the string is surrounded by <ROOT></ROOT>. So I will next I will work on triming that off the string and then populate my Send Mail Task.
This is how I trimed off the <ROOT></ROOT>:
Dts.Variables(
"EmailAddressString").Value = Replace(Dts.Variables("EmailAddressString").Value,
"<ROOT>",
Dts.Variables(
"EmailAddressString").Value = Replace(Dts.Variables("EmailAddressString").Value,
";</ROOT>",
Thanks again everyone for the help!
Reach for the unknown! -
I am experiencing an unexplainable behavior with the Execute SQL Task control in SSIS 2012. The following is a description of how to simulate
the issue I will attempt to describe:
1. Create a package and add two variables User::varTest1 and User::varTest2 both of String type with default value of "Select GetDate()"
for each, have shown this to not matter as the same behavior occurs when using a fixed string value or empty string value.
2. Add a new Execute SQL Task to the control flow.
3. Configure an OLE DB connection.
4. Set SQLSourceType = "Direct Input"
5. Set the ResultSet property of the task to "Single Row"
6. In the ResultSet tab add two results as follows:
Result Name: returnvalue1, Variable Name: User::varTest1
Result Name: returnvalue2, Variable Name: User::varTest2
7. Set an expression for the SqlStatementSource property with a string value of "Select 'Test' returnvalue1, 'Testing' returnvalue2'"
The idea is that the source would be dynamically set in order to run a t-sql statement which would have dynamic values for database name
or object that would be created at runtime and then executed to set the user variable values from its resultset. Instead what occurs is that a DBNull error occurs.
I am not sure if anyone else has experienced this behavior performing similiar actions with the Execute SQL Task or not. Any help would be
appreciated. The exact message is as follows:
[Execute SQL Task] Error: An error occurred while assigning a value to variable "varRestoreScript": "The type of the value
(DBNull) being assigned to variable "User::varRestoreScript" differs from the current variable type (String). Variables may not change type during execution. Variable types are strict, except for variables of type Object.
User::varRestoreScript is the first return value. And even with the a dummy select the same result occurs. I have narrowed the issue down
to the T-SQL Statement structure itself.
The following works just fine within the execute sql task control as long as no resultset is configured for return:
"Declare @dynamicSQL nvarchar(max)
Select @dynamicSQL = name
From sys.databases
Where name = 'master'
Select atest_var1=@dynamicSQL, atest_var2='static'"
I have tried various iterations of the script above with no success. However, if I use the following derivative of it the task completes
successfully and variables are set as expected. This will not work for my scenario however as I need to dynamically build a string spanning multiple resultsets to build one of the variable values.
"Select atest_var1=name, atest_var2='static'
From sys.databases
Where name = 'master'
I have a sample package which can reproduce this issue using the above code. You can get to that through the post on www.sqlservercentral.com/Forums/Topic1582670-364-1.aspx
ScottArthur, the query when executed doesn't return a null value for the @dynamicSQL variable. It returns "master" as a string value. Even the following fails which implements that suggestion:
Declare @dynamicSQL as nvarchar(max)
Select @dynamicSQL = name
From master.sys.databases
Where name = 'master' -- (or any other DB name)
I believe I have found the cause of the issue. It is datatype and size related. The above script will properly set the variables in the resultset as long as you don't use nvarchar(max) or varchar(max). This makes the maximum data size for
a String variable 4000 characters whether unicode or non-unicode typed. -
Using Union in Execute SQL Task
I am using the following SQL statement in an Excute SQL Task:
declare @RespAreaSubAreaID int, @UserLevelID int, @SubmittedByUserID int, @RespAreaID int, @SubAreaID int
Set @RespAreaSubAreaID = ?
Set @SubmittedByUserID = ?
Set @UserLevelID = ?
set @RespAreaID = ?
set @SubAreaID = ?
select users.User_EmailAddress + ';' As CC
from users inner join UserLevelsNotificationFrequencys on users.user_Id = UserLevelsNotificationFrequencys.User_id
where UserLevelID = @UserLevelID and RespAreaSubAreaID = @RespAreaSubAreaID and (NotificationFrequencyID = 4 and users.user_id <> @SubmittedByUserID)
union
select users.User_EmailAddress + ',' As CC
from users inner join UserLevelsNotificationFrequencys on users.user_Id = UserLevelsNotificationFrequencys.User_id
where UserLevelID = @UserLevelID and RespAreaSubAreaID = @RespAreaSubAreaID and (NotificationFrequencyID = 1)
I have my parameter mapped correctly. My results set is set to xml because I want it all in one string to use as a variable named User:CC. On the Result Set tab the result name is 0 and the variable name is User:CC. When I run my package I am getting
the error below. Can I not do a union query in the execute SQL task? I tried to not declare anything and just map to each of the variables that I am passing in the order that they are needed but that didn't work either. Thanks in advance for your help in this
matter.
[Execute SQL Task] Error: Executing the query "declare @RespAreaSubAreaID int, @NotificationID
in..." failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection
not established correctly.
Reach for the unknown!Thank you for your reply but I am not using the Data Flow. All my work is happening on the Control Flow. I am looping through a set of records and emailing them to the correct
people. Setting my result set to XML worked for the To Line (See my earlier post Execute SQL task for Email ToLine using COALESCE and two variables) and now I am working on the CC line which is more complicated because it uses a union statement.
Reach for the unknown! -
Hi there,
I have this issue with my Execute SQL Task Failing. I am trying to execute a sp using an execute sql task. The execute statement is contained in a variable (exec [sp_name] par1, par2) that I have declared at the package level. Now inside the exec sql
tak, I am calling this variable. Now when I try to execute this task, it fails and I get the following:
[Execute SQL Task] Error: Executing the query "EXEC CTL_ISRT_A 55,1" failed with the following error: "Could not find stored procedure 'CTL_ISRT_A'.". Possible failure reasons: Problems with the query, "ResultSet" property not
set correctly, parameters not set correctly, or connection not established correctly.
There is a stored procedure called "CTL_ISRT_A" in the db and I am able to execute it from SQL Server. This sp is inserting a new row in the table and it returns @@IDENTITY.
I tried setting the result set to a 'Single Row' and tried assigning the value to a variable but it didnt help. Could someone help me here?
Thanks in advancereturn it as an output parameter
ie make sp like below
ALTER PROCEDURE [devdba].[M_CTL_ISRT]
@F_ID INT
, @PR_IND BIT
, @Debug bit = 0
, @IDVal int = 0 OUTPUT
AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorMsg varchar(5000)
DECLARE @USR_ID AS INT = 1;
INSERT INTO TBL_D (F_ID, PR_IND, USR_ID,CRE_DT, LAST_MODD_USR_ID, LAST_MODD_DT)
VALUES (@F_ID, @PR_IND, @USR_ID, GETDATE(), @USR_ID, GETDATE())
SELECT @IDVal= @@IDENTITY
END
Then in execute sql task call it as
EXEC devdba].[M_CTL_ISRT] ?,?,0,? OUT
then in parameter tab pass required variables and for last parameter make direction as Output and you'll get identify value stored in it.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
when debugging SSIS, the "Execute SQL Task" runs a stored procedure and returns the expected value. When running the package a second time, the task returns an unexpected value. When running in VS2012 SQL editor, everything operates as expected.
Please help me debug how to get the stored proc to return the same value every time the SSIS Package is run. thanks!
Here is the sequence of events and what happens....
Look for a Positor that matches the Application, Host, and User
No matching PositorId is found, Creates new Positor row, returns that new PositorId
Use PositorId to upload some data (Every thing works)
re-run/debug the ssis pacakge
Look for a Positor that matches the Application, Host, and User
<No clue what is happening>
Returns -1 (SHOULD BE the same PositorId value returned in #2)
"Execute SQL Task" Setup: No edits to Result Set nor Expressions
"Execute SQL Task" Setup: GENERAL
"Execute SQL Task" Setup: PARAMETER MAPPING
SP called by "Execute SQL Task"
CREATE PROCEDURE [posit].[Return_PositorId]
AS
BEGIN
DECLARE @PositorId INT = [posit].[Get_PositorId]();
IF (@PositorId IS NULL)
BEGIN
DECLARE @ProcedureDesc NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
DECLARE @PositorNote NVARCHAR(348) = N'Automatically created by: ' + @ProcedureDesc;
EXECUTE @PositorId = [posit].[Insert_Positor] @PositorNote;
END;
RETURN @PositorId;
END;
Supporting SQL Objects:
CREATE FUNCTION [posit].[Get_PositorId]
RETURNS INT
AS
BEGIN
DECLARE @PositorId INT = NULL;
SELECT TOP 1
@PositorId = [p].[PO_PositorId]
FROM [posit].[PO_Positor] [p]
WHERE [p].[PO_PositorApp] = APP_NAME()
AND [p].[PO_PositorHost] = HOST_NAME()
AND [p].[PO_PositorUID] = SUSER_ID();
RETURN @PositorId;
END;
GO
CREATE PROCEDURE [posit].[Insert_Positor]
@PositorNote NVARCHAR(348) = NULL
AS
BEGIN
DECLARE @ProcedureDesc NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
SET @PositorNote = COALESCE(@PositorNote, N'Automatically created by: ' + @ProcedureDesc);
DECLARE @Id TABLE
[Id] INT NOT NULL
INSERT INTO [posit].[PO_Positor]([PO_PositorNote])
OUTPUT [INSERTED].[PO_PositorId]
INTO @Id([Id])
VALUES(@PositorNote);
RETURN (SELECT TOP 1 [Id] FROM @Id);
END;
GO
CREATE TABLE [posit].[PO_Positor]
[PO_PositorId] INT NOT NULL IDENTITY(0, 1),
[PO_PositorApp] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorApp] DEFAULT(APP_NAME()),
CONSTRAINT [CL__PO_Positor_PO_PositorApp] CHECK([PO_PositorApp] <> ''),
[PO_PositorName] NVARCHAR(256) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorName] DEFAULT(SUSER_SNAME()),
CONSTRAINT [CL__PO_Positor_PO_PositorName] CHECK([PO_PositorName] <> ''),
[PO_PositorHost] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorHost] DEFAULT(HOST_NAME()),
CONSTRAINT [CL__PO_Positor_PO_PositorHost] CHECK([PO_PositorHost] <> ''),
[PO_PositorSID] VARBINARY(85) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorSID] DEFAULT(SUSER_SID()),
[PO_PositorUID] INT NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorUID] DEFAULT(SUSER_ID()),
[PO_PositorNote] VARCHAR(348) NULL CONSTRAINT [CL__PO_Positor_PO_PositorNote] CHECK([PO_PositorNote] <> ''),
[PO_tsInserted] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__PO_Positor_PO_tsInserted] DEFAULT(SYSDATETIMEOFFSET()),
[PO_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__PO_Positor_PO_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
CONSTRAINT [UX__PO_Positor_PO_RowGuid] UNIQUE NONCLUSTERED([PO_RowGuid]),
CONSTRAINT [UK__Positor] UNIQUE CLUSTERED ([PO_PositorApp] ASC, [PO_PositorHost] ASC, [PO_PositorUID] ASC),
CONSTRAINT [PK__Positor] PRIMARY KEY ([PO_PositorId] ASC)
GO
ssdThe error is in item 7: Returns -1 (SHOULD BE the same PositorId value returned in #2); but no error message is returned or thrown from SSIS.
The error message indicated referential integrity is not upheld when inserting records. This error message occurs AFTER the Execute SQL Task successfully completes; the E.SQL Task returns -1. The executed SQL code will not allow values less than 0
([PO_PositorId] INT NOT NULL IDENTITY(0, 1),)
[Platts Valid [41]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E2F.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E2F Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E2F Description:
"The INSERT statement conflicted with the FOREIGN KEY constraint "FK__PricingPlatts_Posit_PositorId". The conflict occurred in database "Pricing", table "posit.PO_Positor", column 'PO_PositorId'.".
The aforementioned FOREIGN KEY constraint is due to the value being returned by the Execute SQL Task.; therefore, the error lies in the value returned by the Execute SQL Task.
Maybe you are looking for
-
Photoshop CS 5 12.0.4 stopped opening any images but JPEG's!
Running a MacBook Pro, 17in, 2.93 Dual Core Intel, 8 GB RAM, OS 10.6.8. All programs and plugins are 64 bit compatable and have worked just fine for months and months. I've been using PS 5 and LR 4.1 for a LONG time. I have several NIK plugins, non
-
My wife has an iphone 5. Has magically stopped working.
One night it was working fine, the next morning it would not connect to her service provider, it would just be stuck in a "searching" mode. We took it to the cell phone service provider, they said to update to the new iOS. OK, we did that, then at
-
Trying to install the classic system folder
Hi All, I have 10.4.11 installed on my G4 Cube and would like to use OS9 applications. I understand that I have to use the Classic environment and I have followed the apple instructions to restart the MAC with the OS9 disk and install. However, once
-
Changed to Uverse from DSL, TC won't work
We recently switched our home business network from AT&T DSL service to Uverse. I can't get the Time Capsule to stop flashing amber. I have tried to configure it through our computers (including while directly wired from the Uverse router) and they s
-
Error when installing APEX 3 on Oracle 11g !!
I have Oracle db 11g on Windows Vista and there is no problem with the database. The problem is when I try to install Oracle Application Express (Apex) 3. After unzipping the Apex zip file to somewhere on my hard disk, I log to the database as sysdba