Exec SQL Task: Capture Return Code Of Stored Proc Not Working

May 19, 2006

I am just trying to capture the return code from a stored proc as follows and if I get a 1 I want the SQL Task to follow a failure(red) constrainst workflow and send a SMTP mail task warning the customer. How do I achieve the Exec SQL Task portion of this, i get a strange error message [Execute SQL Task] Error: There is an invalid number of result bindings returned for the ResultSetType: "ResultSetType_SingleRow".



Using OLEDB connection, I utilize SQL: EXEC ? = dbo.CheckCatLog

EXEC SQL Task Editer settings:
RESULTSET: Single Row
PARAMETER MAPPING: User::giBatchID
DIRECTION: OUTPUT
DATATYPE: LONG
PARAMETER NAME: 0

PS-Not sure if I need my variable giBatchID which is an INT32 but I thought it is a good idea to feed the output into here just in case there is no way that the EXEC SQL TASK can chose the failure constrainst workflow if I get a 1 returned or success constraint workflow if I get a 0 returned from stored proceedure





CREATE PROCEDURE CheckCatLog
@OutSuccess INT
AS

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @RowCountCAT INT
DECLARE @RowCountLOG INT

---these totals should match
SELECT @RowCountCAT = (SELECT Count(*) FROM mydb_Staging.dbo.S_CAT)
SELECT @RowCountLOG = (SELECT Count(*) FROM mydb_Staging.dbo.S_LOG)
--PRINT @RowCountCAT
--PRINT @RowCountLOG
BEGIN
IF @RowCountCAT <> @RowCountLOG
--PRINT 'Volume of jobs from the CAT file does not match volume of jobs from the LOG file'
--RETURN 1
SET @OutSuccess = 1
END
GO

Thanks in advance

Dave

View 6 Replies


ADVERTISEMENT

How To Capture The Return Code Of An Execute Process Task

Jan 18, 2008

Can anyone tell me how to capture the return code of a process launched by an Execute Process Task? I am able to capture the output by using the StandardOutputVariable but can't seem to capture the actual code.

View 4 Replies View Related

Capture Return Value From Stored Procedure, Use Same In Code Behind Page

Apr 18, 2007

My stored procedure works and codes is working except I need to capture the return value from the stored procedure and use that value in my code behind page to indicate that a duplicate record entry was attempted.  In my code behind file (VB) how would I capture the value "@myERROR" then display in the label I have that a duplicate entry was attempted.
Stored ProcedureCREATE PROCEDURE dbo.usp_InsertNew @IDNumber         nvarchar(25), @ID  nvarchar(50), @LName  varchar(50), @FName  varchar(50)
AS
 DECLARE @myERROR int    -- local @@ERROR      , @myRowCount int  --local @@rowcountBEGIN  -- See if a contact with the same name and zip code exists IF EXISTS (Select * FROM Info   WHERE ID = @ID)   BEGIN    RETURN 1END ELSEBEGIN TRAN    INSERT INTO Info(IDNumber, ID, LName,             FName) VALUES (@IDNumber, @ID, @LName,             @FName)             SELECT @myERROR = @@ERROR, @myRowCount = @@ROWCOUNT If @myERROR !=0 GOTO HANDLE_ERROR
                               COMMIT TRAN RETURN 0 HANDLE_ERROR:  ROLLBACK TRAN  RETURN @myERROR      ENDGO
asp.net page<asp:SqlDataSource ID="ContactDetailDS" runat="server" ConnectionString="<%$ ConnectionStrings:EssPerLisCS %>"            SelectCommand="SELECT * FROM TABLE_One"                        UpdateCommand="UPDATE TABLE_One WHERE ID = @ID"                         InsertCommand="usp_InsertNew" InsertCommandType="StoredProcedure">                        <SelectParameters>                <asp:ControlParameter ControlID="GridView1" Name="ID" PropertyName="SelectedValue" />            </SelectParameters>             </asp:SqlDataSource>
 

View 2 Replies View Related

Return Error Code (return Value) From A Stored Procedure Using A Sql Task

Feb 12, 2008


I have a package that I have been attempting to return a error code after the stored procedure executes, otherwise the package works great.

I call the stored procedure from a Execute SQL Task (execute Marketing_extract_history_load_test ?, ? OUTPUT)
The sql task rowset is set to NONE. It is a OLEB connection.

I have two parameters mapped:

tablename input varchar 0 (this variable is set earlier in a foreach loop) ADO.
returnvalue output long 1

I set the breakpoint and see the values change, but I have a OnFailure conditon set if it returns a failure. The failure is ignored and the package completes. No quite what I wanted.

The first part of the sp is below and I set the value @i and return.


CREATE procedure [dbo].[Marketing_extract_history_load_TEST]

@table_name varchar(200),

@i int output

as

Why is it not capturing and setting the error and execute my OnFailure code? I have tried setting one of my parameter mappings to returnvalue with no success.

View 2 Replies View Related

How To Call AS400 Stored Proc And Evaluate The Return Code?

May 30, 2007

I am trying to use SSIS to update an AS400 DB2 database by calling a stored procedure on the AS400 using an OLE DB command object. I have a select statement running against the SQL Server 2005 that brings back 20 values, all of which are character strings, and the output of this select is piped into the OLE DB command object. The call from SSIS works just fine to pass parameters into the AS400 as long as the stored procedure being called does not have an output parameter defined in its signature. There is no way that I can find to tell the OLE DB command object that one of the parameters is an output (or even an input / output) parameter. As soon as one of the parameters is changed to an output type, I get an error like this:






Code Snippet


Error: 0xC0202009 at SendDataToAs400 1, OLE DB Command [2362]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x8000FFFF.

Error: 0xC0047022 at SendDataToAs400 1, DTS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "OLE DB Command" (2362) failed with error code 0xC0202009. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.

Error: 0xC0047021 at SendDataToAs400 1, DTS.Pipeline: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0202009. There may be error messages posted before this with more information on why the thread has exited.

Information: 0x40043008 at SendDataToAs400 1, DTS.Pipeline: Post Execute phase is beginning.

Information: 0x40043009 at SendDataToAs400 1, DTS.Pipeline: Cleanup phase is beginning.

Task failed: SendDataToAs400 1

Warning: 0x80019002 at RetrieveDataForSchoolInitiatedLoans: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

Warning: 0x80019002 at Load_ELEP: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

SSIS package "Load_ELEP.dtsx" finished: Failure.





I really need to know if the call to the AS400 stored procedure succeeded or not, so I need a way to obtain and evaluate the output parameter. Is there a better way to accomplish what I am trying to do? Any help is appreciated.

View 3 Replies View Related

Return Code From Exec

Sep 30, 2004

Hi
I have a maintenance proceudre that trims data tables on the live site, but prior to trimming i need to execute procs via linked servers at four seprate locations (subscribers) to ensure all of their data is up to date before the trim happens (the deletes are blocked at the subs). my problem is that if i go
exec @error_id = procname
and an error such as permission being denied or proc missing, the return code
is still 0 - therefor it looks like th proc ran successfully, meanwhile it didnt.
does anyone know how to check for these sorts of erors, so i dont leave this to chance?

thnks
des

View 5 Replies View Related

How To Capture The ResultSet Of EXEC Command In Stored Procedure

Oct 1, 2007



Hi All,

I have created a dynamic SQL STATEMENT , but the result of the execution of that statement matters to me. within stored procedure.

Note: If run the statement using EXEC() command, the result gets displayed on the SQL Editor.
But I DO NOT KNOW HOW to Capture that value.

Any idea how to capture as I would like capture the result and stored it in a table.

Thank you.
--Israr

View 4 Replies View Related

If Exists Capture Value Returned From Stored Proc

Feb 26, 2006

I have a stored proc with a query which checks whether an identical
value is already in the database table. If so, it returns a value of 1.
How do I caputure this value in an asp.net page in order to display a
message accordingly? (using ASP.NET 1.1)

Currently my stored proc looks something like this (snippet only):
If Exists(
SELECT mydoc WHERE....
)
Return 1
Else
...INSERT INTO.... code here.

View 2 Replies View Related

Capture Stored Proc Output To File

Jan 8, 2001

I am running a stored proc that does many updates. I want to capture the results of the stored proc in a text file. Results returned such as, 18 rows affected (the stuff that shows in results pane of query analyzer). Do I have to run the stored proc in batch mode to do this and capture via the output file in OSQL? I also want to capture error messages in case the stored proc aborts in the middle.

I am running SQL Server 7.0 SP2 on Win2K. I am running the stored proc in a DTS package.

Thanks.

Tim

View 3 Replies View Related

Capture A Fresh Copy Of The Stored Proc

Sep 18, 2007

How do I go about if I want to capture a fresh copy of the stored procedure?

Nishi

View 5 Replies View Related

How Does The .net App Capture Raiserror Values From A Stored Proc

Oct 28, 2006

I have been using return values to check the status of my stored procedures called from an application. But how does one read the new raiserror values that are passed with sql server 2005 and using ado.net 2.0. Are they returned as parameters or as a dataset or what?

Thanks

smHaig

View 2 Replies View Related

Exec Stored Proc And Getting The Value

Mar 21, 2008

I've been bangging my head against the wall on this one and its probably something really easy but for the love of god, I can't figure it out.
I have the following stored procedure
  ALTER PROCEDURE [dbo].[InsertUserProjectPhase]
(
@ProjectPhaseID int,
@ProductionEngineerUserID int,
@QuantityCompleted decimal(18, 2),
@BillableHours decimal(18, 2),
@TotalWorkingHours decimal(18, 2),
@DateUpdated datetime,
@UpdatedByUserID int,
@IsDeleted bit
)
AS
SET NOCOUNT OFF;
INSERT INTO User_Project_Phase
(ProjectPhaseID, ProductionEngineerUserID, QuantityCompleted, BillableHours, TotalWorkingHours, DateUpdated, UpdatedByUserID, IsDeleted)
VALUES (@ProjectPhaseID,@ProductionEngineerUserID,@QuantityCompleted,@BillableHours,@TotalWorkingHours,@DateUpdated,@UpdatedByUserID,@IsDeleted);

SELECT ID FROM User_Project_Phase WHERE (ID = SCOPE_IDENTITY())
 
How can I call the above stored procedure (from within another stored procedure) AND save get the return value (the ID).  I tried the following:
 exec @newProjectPhaseID = dbo.InsertProjectPhase @ProjectID=3796,@PhaseID=@PhaseID,@EstimatedQuantity=@EstimatedQuantity,
@EstimatedDuration=@EstimatedDuration,@TotalQuantityCompleted=@TotalQuantityCompleted,
@TotalBilledQuantity=@TotalBilledQuantity,@QuantityType=@QuantityTypeID,@StatusID=@StatusID,
@CreatedByUserID=18569  
Where @newProjectPhaseID was declared at the top as int.  The numbers you see in there will be replaced with variables.  They are there now because I'm executing the sp directly in management studio.
 Of course, the above doesn't work.  I was hoping that the return value form InsertProjectPhase would be saved in @newProjectPhaseID but I get an error.
Any help will be appreciated.  THANKS A MILLION!
-Psion
 
 
 
 

View 2 Replies View Related

Exec Stored Proc

Sep 30, 2004

I need some help with the following store proc, something is wrong but I just dont see it.
Thanks
btw I am no expert at sp so something might be complety wrong.

ALTER PROCEDURE dbo.GetSearchByDateRange

(
@strColumnNamenvarchar (50),
@dtDate1 Date,
@dtDate2 Date
)
as

EXEC ('SELECT * FROM Customers WHERE ' + @strColumnName + ' BETWEEN ' + ''' + @dtDate1 + ''' + ' AND ' + ''' + @dtDate2 + '''')

View 7 Replies View Related

Exec Stored Proc

Aug 7, 2007

Hi Guys, I created the following stored proc which calls another stored procs as shown below.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Create Procedure [dbo].[rpt_CompareDB](@tbl_name varchar(400),@DB_name1 varchar(400),@DB_name2 varchar(400))

AS

declare @result1 varchar(8000),

@result2 varchar(8000),

@table_name varchar (400),

@DB1 varchar(400),

@DB2 varchar(400),

@table_final1 varchar(400),

@table_final2 varchar(400),

@DB_detail1 varchar(400),

@DB_detail2 varchar(400)

set @table_name = @tbl_name
set @DB1 = @DB_name1

set @DB2 = @DB_name2

set @DB_detail1 = @DB1 + '.mfgq_live'

set @DB_detail2 = @DB2 + '.mfgq_live'

set @table_final1 = @DB_detail1 + '.dbo.' +@table_name

set @table_final2 = @DB_detail2 + '.dbo.' +@table_name

exec GetColumnNamesString @DB_detail1,@table_name,@result1 output

exec GetColumnNamesString @DB_detail2,@table_name,@result2 output

exec CompareTables @table_final1,@table_final2,@result1,@result2


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
but, when I tried to excute it, I am getting an error.

Here is how I'm trying to exec the stored proc.

execute dbo.rpt_CompareDB

@tbl_name = 'Attribute'

,@DB_name1 = 'Green'

,@DB_name2 = 'devlue02'

FYI, It works fine if you run the query itself instead of executing the stored proc.

Any idea is appreciated

View 3 Replies View Related

SQL Error When Using EXEC In Stored Proc

Jul 10, 2006

I have the following stored proc that is providing the following error - Server: Msg 156, Level 15, State 1, Line 79[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'ORDER'.
The sp works fine if the DateOfBirth elements are removed. I think it is something to do with the way in which the date variable is incorporated into the string that will be executed by the EXEC command but I'm unsure as to what is wrong.
CREATE PROCEDURE dbo.GetPersonsByName (@FirstName varchar(50)=NULL, @FamilyName varchar(50)=NULL, @DateOfBirth datetime=NULL)
AS
EXEC ('SELECT  PersonId, Title, FirstName, FamilyName , AltFamilyName, Sex, DateOfBirth, Age, DateOfDeath, CauseOfDeath, Height, Weight, ABO, RhD, Comments, LocalIdNo, NHSNo, CHINo, Hospital, HospitalNo, AltHospital, AltHospitalNo, EthnicGroup, Citizenship, NHSEntitlement, HomePhoneNo, WorkPhoneNo, MobilePhoneNo, CreatedBy, DateCreated, UpdatedBy, DateLastUpdated
 FROM vw_GetPersons  WHERE FirstName LIKE ''%' + @FirstName + '%'' AND  FamilyName LIKE ''%' + @FamilyName + '%'' AND DateOfBirth = '+ @DateOfBirth +' ORDER BY FamilyName, FirstName')
GO

View 12 Replies View Related

Exec Stored Proc In Different Database

Apr 17, 2001

I have a set of stored procedures copied into several databases (similar table structures but different data). I would like to avoid maintaining so many versions of the same procedures, so want to put the stored procs in a common database and execute it from there, e.g.
exec common_db..the_procedure
However, when you do that, the procedure executes in the context of common_db, not in the context of the calling proc's database. Is there a way of calling a procedure so that the calling proc's context is used?

View 1 Replies View Related

Exec Stored Proc Question

Dec 4, 2000

I am working on a project to re-code SQL Anywhere to T-SQL (SQL Server 2000) and am encountering many instances where the original code contained a SELECT statement that calls a stored procedure. T-SQL does not allow calling a procedure from a SELECT statement as far as I can see. Does anyone have any good ideas on working around this??

Thanks

View 1 Replies View Related

How To Exec Stored Proc Dynamically

Jul 23, 2005

HelloI have 2 procedures setup in master database, sp_RebuildIndexesMain andsp_RebuildIndexesSubThe Sub just shows and execute DBCC commands for passed databasecontextsp_RebuildIndexesSub(@listOnly bit=0, @maxfrag Decimal=30.0)This runs fine if I do pubs..sp_RebuildIndexesSubHowever when run thru. the Main proc, I get Incorrect syntax near'pubs'.The main proc isCreate Proc sp_RebuildIndexesMain(@dbName sysname, @listOnly bit=0,@maxFrag Decimal=30.0)AsBeginSet NOCOUNT ONDeclare crDbs CURSOR ForSelect CATALOG_NAME From INFORMATION_SCHEMA.SCHEMATAWhere CATALOG_NAME NOT IN ('tempdb', 'master', 'msdb', 'model','distribution', 'Northwind', 'pubs')And CATALOG_NAME Like @dbNameDeclare @execstr nvarchar(2000)Open crDbsFetch crDbs INTO @dbNameIf (@@FETCH_STATUS<>0) --Then no matching databasesBeginClose crDbsDeallocate CrDbsPrint 'No databases were found that match ''' + @dbName + ''''Return -1EndWhile(@@FETCH_STATUS=0)BeginPrint Char(13) + 'Rebuilding indexes on ' + @dbNamePrint Char(13)Set @execstr = @dbName + '..sp_RebuildIndexesSub 'EXEC sp_executesql @execstr, N'@listOnly bit, @maxFrag Decimal',@listOnly, @maxFragFetch crDbs INTO @dbNameEndClose crDbsDeallocate CrDbsReturn 0EndthanksSunitJoin Bytes!

View 5 Replies View Related

Exec SQL Task (stored Procedures)

Jan 24, 2007

Hi,

Can anyone tell me how to pass parameters from one exec sql task to other ?... (I used stored proc in 1st exec sql task) and passed input parameter (default value set using a variable A) and stored the output parameter value in another variable B.

In the 2nd exec sql task , I passed the output param ( value of B) and doing insert into table xyz...

I get errors (in passing int and string values) . I tried using ole-db as well as ado.net.

Kindly give sample example.

Thanks,









View 1 Replies View Related

Stored Proc Not Working, HELP PLEASE!

May 9, 2005

I'm pretty new when it comes to Stored Procs, and for some reason, the CurAge isn't coming up with an actual numeric value. Does anyone see what I am doing wrong?

CREATE PROCEDURE sp_GetTargetProducts
@hmid int,
@wtid int
AS
DECLARE @CurAge INT
if exists(
SELECT LastName, FirstName, HMID, DATEDIFF (YY , BirthDate, GetDate()) As CurAge
FROM Members
WHERE hmid = @hmid
)
BEGIN
SELECT DISTINCT Product, ProductAdvance, AgeBottom, AgeTop, ProductName, ProductDesc, ProductPrice, ProductPicture
FROM Products
WHERE wtid = @wtid
AND AgeBottom <= @CurAge
AND AgeTop >= @CurAge
GROUP BY Product, ProductAdvance, AgeBottom, AgeTop, ProductName, ProductDesc, ProductPrice, ProductPicture
return(1)
END
else
return(0)
GO

View 6 Replies View Related

Can't Get Stored Proc To Return A Value

Feb 12, 2008

Hi,I'm having trouble getting a stored procedure to return a single
integer value.  Here's a short
version:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~set ANSI_NULLS ONset
QUOTED_IDENTIFIER ONGOALTER PROCEDURE
[dbo].[Perm_Import_CJ]AS/* bunch of stuff removed */DECLARE
@NoCategory intSELECT @NoCategory = COUNT(*) FROM table WHERE CategoryID IS
NULL/* print @NoCategory */RETURN
@NoCategory~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~If I uncomment "print
@NoCategory" it prints exactly the number it's supposed to, so there is no
problem with any of the queries in the stored procedure.  Then, in the code,
this is what I'm doing:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Dim dbConn
As New
SqlConnection(WebConfigurationManager.ConnectionStrings("ConnectionName").ConnectionString)Dim
cmd As New SqlCommand("StoredProc", dbConn)cmd.CommandType =
CommandType.StoredProceduredbConn.Open()Dim intNoCategory As Integer =
CInt(cmd.ExecuteScalar())dbConn.Close()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~But,
and here's the problem ---> Even though @NoCateogry prints as the correct number, by the time it gets to intNoCategory in the code, it is ALWAYS zero.I have no idea what I am doing wrong. 
Thanks in advance for any help!Casey 

View 4 Replies View Related

Return Value From Stored Proc?

Jun 8, 2005

I need a stored procedure to return a value to my .NET app (ascx). The value will tell the app if the stored procedure returned any values or not. For example, if the Select SQL statement in the stored procedure returns no rows, the stored procedure could return a zero to the .NET app, otherwise it could return the number of rows or just a one to the .NET app.Anyone know how to do this?Thanks!

View 1 Replies View Related

PLEASE PLEASE HELP - How Can I Get A Return Value From A SQL Stored Proc Is ASP.NET?

Nov 30, 2006

Hi. I'm sorry to bother all of you, but I have spent two days lookingat code samples all over the internet, and I can not get a single oneof them to work for me. I am simply trying to get a value returned tothe ASP from a stored procedure. The error I am getting is: Item cannot be found in the collection corresponding to the requested name orordinal.Here is my Stored Procedure code.set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGoALTER PROCEDURE [dbo].[sprocRetUPC]@sUPC varchar(50),@sRetUPC varchar(50) OUTPUTASBEGINSET NOCOUNT ON;SET @sRetUPC = (SELECT bcdDVD_Title FROM tblBarcodes WHERE bcdUPC =@sUPC)RETURN @sRetUPCENDHere is my ASP.NET code.Protected Sub Page_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs) Handles Me.LoadDim oConnSQL As ADODB.ConnectionoConnSQL = New ADODB.ConnectionoConnSQL.ConnectionString = "DSN=BarcodeSQL"oConnSQL.Open()Dim oSproc As ADODB.CommandoSproc = New ADODB.CommandoSproc.ActiveConnection = oConnSQLoSproc.CommandType = ADODB.CommandTypeEnum.adCmdStoredProcoSproc.CommandText = "sprocRetUPC"Dim oParam1Dim oParam2oParam1 = oSproc.CreateParameter("sRetUPC",ADODB.DataTypeEnum.adVarChar,ADODB.ParameterDirectionEnum.adParamOutput, 50)oParam2 = oSproc.CreateParameter("sUPC", ADODB.DataTypeEnum.adVarChar,ADODB.ParameterDirectionEnum.adParamInput, 50, "043396005396")Dim resres = oSproc("sRetUPC")Response.Write(res.ToString())End SubIf I put the line -oSproc.Execute()above the "Dim res" line, I end up with the following error:Procedure or function 'sprocRetUPC' expects parameter '@sUPC', whichwas not supplied. I thought that oParam2 was the parameter. I was alsounder the assumption that the return parameter has to be declaredfirst. What am I doing wrong here?

View 8 Replies View Related

Update Stored Proc Not Working

Jan 12, 2005

I'm trying to run a UPDATE stored proc to allow my users to update records that are in a datagrid. What the update proc looks like is as follows:

Proc sp_UpdateRecords
@fname nvarchar(30), @lname nvarchar(30), @address1 nvarchar(50), @address2 nvarchar(50), @CITY nvarchar(33), @ST nvarchar(10), @ZIP_OUT nvarchar(5), @ZIP4_OUT nvarchar(4), @home_phone nvarchar(22), @autonumber int
AS
UPDATE NCOA20040603 SET fname=@fname, lname=@lname, address1=@address1, address2=@address2, CITY=@CITY, ST=@ST, ZIP_OUT=@ZIP_OUT, ZIP4_OUT=@ZIP4_OUT, home_phone=@home_phone
WHERE autonumber=@autonumber

The message I'm getting is as follows:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index


What could be the problem

Any ideas are appriciated -- Thanks in advance
RB

View 5 Replies View Related

Wht Should Be Stored Proc Code??

Jul 25, 2007

Hey all,
I have access as my front end and has upsized to sql server 2000.
DLookup function that was in VBA code before was working fine. but after upsizing there is the problem in that code...
What could be the alternative for DLookup Function in sql server..
Do i have to write a view or stored procedure..?

Any Help appreciated.

View 14 Replies View Related

Stored Proc In SQL Code

Dec 10, 2007

Using SQL Server 2005. Writing SQL code but I need to use the reults from two different stored proc. How do you code a select statement using a stored proc. I know when using views you just use the view name in the From or join statemnt, but do you do the same with using a Stored proc. Thank you for your help. David

View 5 Replies View Related

Get A Return Value From An Insert Without Using A Stored Proc.

Oct 31, 2006

hi all, lets say i have this insert command being executed from C# to a SQL Db. //store transaction log
SqlCommand cmdStoreTrans = new SqlCommand("INSERT into Transactions(ImportID,ProfileID,RowID) values (@ImportID,@ProfileID,@RowID);",conn);
cmdStoreTrans.Parameters.Add("@ImportID",importId);
cmdStoreTrans.Parameters.Add("@ProfileID",profileId);
cmdStoreTrans.Parameters.Add("@RowID",i);
try
{
conn.Open();
cmdStoreTrans.ExecuteNonQuery();
conn.Close();
}
catch(SqlException ex)
{
throw(ex);
}I need the new Identity number of that record added.  how can i get that within THIS Sqlcommand.  Currently im closing the connection, creating a new command with 'SELECT MAX(id) from transactions" and getting the value that way, im sure there is a easier way keeping it all within one command object? someone mentioned using something liek @@Identity any help appreciatedTIA, mcm

View 2 Replies View Related

Return @@rowcount From Stored Proc

Sep 24, 2007

 HiI'm using an sqldatasource control in my aspx page, and then executing it from my code behind page (SqlDataSource1.Insert()), how do i retrieve the number of rows (@@rowcount) which have been inserted into the database and display it in my aspx page.  I am using a stored procedure. thanks 

View 1 Replies View Related

Stored Proc How To Return A Single Value

Oct 9, 2007

How do I return a value in a stored procedure? I want to return a value for TheQuarterId below but under all test conditions am only getting back a negative one. Please help! create PROCEDURE [dbo].[GetQuarterIdBasedOnDescription]
(
@QuarterString nvarchar(10),
@TheQuarterId int output
)
AS

BEGIN
SELECT @TheQuarterId = QuarterId from Quarter WHERE Description=@QuarterString
END

 

View 1 Replies View Related

Stored Proc Won't Return Correct Value.

Oct 18, 2007

I am using VS 2006, asp.net and C# to call a stored procedure. I want to return a value from the stored procedure into a variable in my C# code. Currently this is not working for me, and I can not figure out whatthe problem is? Can someone please help me out?
I really don't think the problem is in my stored procedure. I can right click on the stored proc and run it withsuccess. If I trace into the C# code though only a negative one (-1) is returned.
On line 5 I have tried the alternate lines of code but this has not worked for me.
     mySqlCommand.Parameters["@TotalRecords"].Direction = ParameterDirection.Output;     mySqlCommand.Parameters["@TotalRecords"].Direction = ParameterDirection.ReturnValue;
Can someone please help me out. I have spent to much time trying to figure this one out.
// C# code to call stored proc.1  try2   {3     SqlCommand mySqlCommand = new SqlCommand("[GetRecordsAssociatedWithRealtor]", mySqlConnection);4     mySqlCommand.Parameters.Add("@RealtorId", SqlDbType.Decimal, 10).Value = RealtorId;5     mySqlCommand.Parameters["@TotalRecords"].Direction = ParameterDirection.InputOutput;6     mySqlCommand.CommandType = CommandType.StoredProcedure;7     RecordsAssociatedWithRealtor = mySqlCommand.ExecuteNonQuery();8   }
// Stored procedure below.USE [REALTOR]GO/****** Object:  StoredProcedure [dbo].[GetRecordAssociatedWithRealtor]    Script Date: 10/18/2007 13:15:18 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[GetRecordAssociatedWithRealtor]( @RealtorId int, @TotalRecords int output)AS BEGIN DECLARE @HouseDetailRecords int DECLARE @RealtorRecords int SELECT  @HouseDetailRecords= RealtorId from Realtor where RealtorId=@RealtorId SELECT  @RealtorRecords = RealtorId from ConstructionDetail where RealtorId=@RealtorId SET     @TotalRecords=SUM(@HouseDetailRecords+@RealtorRecords) RETURN  @TotalRecordsEND

View 5 Replies View Related

Execute Stored Proc And Then Return A Value

Jul 13, 2004

ok I have a stored procedure in my MS-SQL Server database.
It looks something like this.....

CREATE PROCEDURE updatePCPartsList
(
@Descriptionvarchar(255),
@ManCodevarchar(255),
@ProdCodevarchar(255),
@Pricedecimal(6,2),
@Commentsvarchar(255)
)
AS

declare @IDFound bigint
declare @LastChangedDate datetime

select @LastChangedDate = GetDate()
select @IDFound = PK_ID from PCPartsList where ProdCode = @ProdCode

if @IDFound > 0
begin
update PCPartsList set Description = @Description, ManCode = @ManCode, ProdCode = @ProdCode, Price = @Price, Comments = @Comments, LastChanged = @LastChangedDate where PK_ID = @IDFound
end
else
insert into PCPartsList (Description, ManCode, ProdCode, Price, Comments, LastChanged) values(@Description, @ManCode, @ProdCode, @Price, @Comments, @LastChangedDate)
GO

It executes fine so I know i've done that much right....
But what i'd like to know is how I can then return a value - specifically @LastDateChanged variable

I think this is a case of i've done the hard part but i'm stuck on the simple part - but i'm very slowly dragging my way through learning SQL.
Someone help?

View 3 Replies View Related

Newbie: Cannot Get Return Value From Stored Proc

Feb 20, 2007

Good morning, all,

OK, I have read a ton of posting on this issue, but either they don't give enough information or they are for packages which use the Execute SQL command, whereas I am using the OLE DB Command Data Flow Transformation.

I have an Excel spreadsheet that we are receiving from agencies with rows of client data which I have to load into an application that is ready to go live. I also have a stored procedure spClientsInsertRcd, which was written for the application. In the normal flow of the application, the stored procedure is called from a Coldfusion page, which does some processing prior to calling it. So, I have written a 'wrapper' stored procedure, spImportAgencyData, which does the processing and then calls the spClientInsertRcd.

My dataflow has the following components:

An Excel Source, containing my test data, consisting of just one row of data,

which points to a

Derived Column Transformation, which reformats the SSN and adds a user variable, named returnValue with an Expression value of @[User::returnvariable] set to a four-byte signed integer, which (i think) I need to get the value out of the stored procedure.

which points to a

Data Conversion Transformation, which takes care of all the datatype conversions

which points to a

OLE DB Command, which contains the following as the SQL Command:

exec ?= spImportAgencyData ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?

In the OLE DB Command, I have mapped returnValue, my user variable to @RETURN_VALUE.

Right now, I am in initial testing. The dataflow shows that it is succeeding, but my one data record for testing is not getting inserted. I need to get the value of returnValue to figure out what is happening.

How do I get the value of the returnValue? I have tried putting a recordset destination after the OLE DB command, but that just gives me the data that went into the OLE DB Command.

Thanks,
Kathryn

View 2 Replies View Related

Invalid Return Value From Stored Proc From VC++ 6.0

Oct 27, 2006

I have a stored procedure that takes a computer name (nvarchar) and either updates a time stamp in a matching row or adds a new row when no match is found based on the computer name (replicates a set of rows in another table as well in the case of not found).

When the row is unmatched, an output param (int) is set to 1 indicating it is new. When found, a zero is placed into the output parameter.

This stored procedure worked fine until we recently upgraded to SQL Server Express (2005).

C++ code:

_bstr_t conn_str = CONN_STR;
conn_str += (LPCTSTR)_server_name;

try
{
_ConnectionPtr epi_conn;
_CommandPtr cmd("ADODB.Command");
_ParameterPtr param;
long addfg;
_variant_t var_addfg;

//
// connect to database
//
epi_conn.CreateInstance(__uuidof(Connection));
epi_conn->Open(conn_str,"","",adConnectUnspecified);

cmd->ActiveConnection = epi_conn;
cmd->CommandText = "qry_DBUpdWorkstation";
cmd->CommandType = adCmdStoredProc;

//
// setup stored procedure call
//
param = cmd->CreateParameter (_bstr_t("@s_computer_name"), adVarChar, adParamInput, 31);
cmd->Parameters->Append(param);
param->Value = client_name;

param = cmd->CreateParameter (_bstr_t("@l_addfg"), adInteger, adParamOutput, 4);
cmd->Parameters->Append(param);

//
// debug output
//
if (trace_fp)
{
COleDateTime cur_dt = COleDateTime::GetCurrentTime();
fwprintf(trace_fp, L"%s - clsSrvrCtrlr::UpdWorkstation 1 client=%s",
cur_dt.Format(), client_name);
fflush(trace_fp);
}

cmd->Execute(NULL, NULL, adCmdStoredProc);

var_addfg = cmd->Parameters->Item[_variant_t("@l_addfg")]->Value;
addfg = var_addfg.iVal;

//
// done with stored proc
//
epi_conn->Close();

if (trace_fp)
{
COleDateTime cur_dt = COleDateTime::GetCurrentTime();
fwprintf(trace_fp, L"%s - clsSrvrCtrlr::UpdWorkstation 2 var_addfg.vt=%d, var_addfg.iVal=%d",
cur_dt.Format(), var_addfg.vt, var_addfg.iVal);
fflush(trace_fp);
}



and the stored proc:

set ANSI_NULLS OFF

set QUOTED_IDENTIFIER OFF

GO

-- Database Version 5.5.0

ALTER PROCEDURE [dbo].[qry_DBUpdWorkstation]

@s_computer_name nvarchar(31),

@l_addfg int OUTPUT

AS

SET NOCOUNT ON

DECLARE @d_update_dt datetime

DECLARE @l_msg_cd int

DECLARE @b_view_local bit

DECLARE @b_view_global bit

DECLARE @l_alert_type smallint

DECLARE @s_sound_file nvarchar(255)

DECLARE @l_wscd int

SELECT @d_update_dt=UpdateDT

FROM dbo.tblWorkstations

WHERE ComputerNameTxt=@s_computer_name

SET @l_addfg = 0

IF @d_update_dt IS NULL

BEGIN

INSERT tblWorkstations (ComputerNameTxt, UpdateDT, OnlineFg)

VALUES (@s_computer_name, GETDATE(), 0)

SET @l_wscd = SCOPE_IDENTITY()

DECLARE msg_cursor SCROLL CURSOR FOR

SELECT SysMsgCd, ViewLocalFg, ViewGlobalFg, AlertTypeVal, SoundFileTxt

FROM tblMsgAlerts

WHERE WorkstationCd = -1

OPEN msg_cursor

FETCH FIRST FROM msg_cursor INTO

@l_msg_cd, @b_view_local, @b_view_global, @l_alert_type, @s_sound_file

WHILE @@fetch_status = 0

BEGIN

INSERT tblMsgAlerts (WorkstationCd, SysMsgCd, ViewLocalFg, ViewGlobalFg, AlertTypeVal, SoundFileTxt)

VALUES (@l_wscd, @l_msg_cd, @b_view_local, @b_view_global, @l_alert_type, @s_sound_file)

FETCH NEXT FROM msg_cursor INTO

@l_msg_cd, @b_view_local, @b_view_global, @l_alert_type, @s_sound_file

END

CLOSE msg_cursor

DEALLOCATE msg_cursor

SET @l_addfg = 1

END

ELSE

BEGIN

UPDATE tblWorkstations

SET UpdateDT = GETDATE()

WHERE ComputerNameTxt=@s_computer_name

END



The stored proc ALWAYS returns 0 but will execute the code to insert the new row when not found and replicate the rows in the second table. Any ideas, suggestions?

Thanks

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved