Execute An SP By Passing Params From Another SP

May 7, 2008

Hi

I am trying to execute a stored procedure from another stored procedure by passing parameters. any idea please.
I have tried with EXECUTE PROC dbo.dxGetMemberActivityData (@author) RETURNING_VALUES RESULT

but I am getrting incorrect sytax near PROC

View 2 Replies


ADVERTISEMENT

Passing Params To SP Using OPEN QUERY

Oct 8, 2014

How to pass parameter values to Stored Procedure using Openquery ?

DECLARE @CenterNumber nvarchar(8)
DECLARE @CenterName nvarchar(100)
DECLARE @tblLeads table(
LeadCount int)
SET @CenterNumber = '98454152'
SET @CenterName = 'neck'

[code]....

View 3 Replies View Related

Report Run OK W/ Default Params But Not Changed Params

Mar 25, 2008

I have a set of reports that run just fine with the default parameters (Country = US). The report returns data within 60 seconds. However, if I change the default parameters, say to Country = UK, the report will run and won't seem to stop. The user will be prompted every few minutes to relogin to the domain (which they are not prompted when they first run the report). On the server, the report is taking up 1 of the four CPU's and is using a huge amount of disk paging.

Here's the kicker. If I go in, change the default parameters to Country = UK and deploy the report, it will run in 60 seconds with the new default parameters. Now I try to run the report by changing the country = US and it locks up when it is executed.


Anybody run into something like this?

Rob

View 5 Replies View Related

HOW To Passing Parameters To EXECUTE Sp_makewebtask

Nov 24, 1999

EXECUTE sp_makewebtask
@outputfile = 'd:WEBmultiple11.htm',
@query = 'SELECT title, price FROM titles' ,
@templatefile = 'd:WEBTemplate.htm',
@dbname = 'pubs', @rowcnt = 5, @whentype = 9

hi, running the above code will create html page. Ineed to pass @price as a parameters, how can I do that, thanks for your help
Ali

View 2 Replies View Related

Execute SQL Task - Passing Variables

Aug 28, 2007

how can you pass variables from one 'Execute SQL Task' to another?

View 9 Replies View Related

Parameter Passing In Execute SQL Task

Mar 20, 2008



Hi All,

I have a Doubt in Parameter Passing in Execute SQL Task.

In Execute SQL Task, I have an Insert query in which I want to pass the Database Name Dynamically i.e. passing it as a parameter.

Eg.
The query is --------- Insert into [?].[dbo].[DimCurrency] values( value1, value2, value3)

I want to pass this Database name using a user variable. But I am not able to do so.

What is the catch in this, Can anybody please help me out.

Thanks & Regards,
kapadia Shalin P.

View 5 Replies View Related

Transact SQL :: Passing Parameter To Execute Task

Aug 6, 2015

In temp table there rae data which start with 1 and 2.I want to select only those record which start with 1 Zone is a parameter to the Execute sql task in ssis package..I have created sample code to test when I am running my query I am not getting anything

create table #temp
( zoneid bigint
)
insert into #temp values(100000000000000000)
insert into #temp values(100000000000000000)
insert into #temp values(100000000000000000)
insert into #temp values(100000000000000000)
insert into #temp values(200000000000000000)
insert into #temp values(200000000000000000)

[code]...

View 6 Replies View Related

Execute SQL Task Fails When Passing A Parameter Using OLE DB

Apr 26, 2008

I have a SSIS Execute SQL Task that calls a stored procedure with a date parameter. The text of the stored procedure is an "INSERT INTO .. SELECT ..." statement. When I run the text in Query Analyzer, it completes successfully. When I call the Stored Procedure, it executes but does not insert the data. Setting ByPass Prepare to True does not affect the outcome. I also used the query directly in the SQL task itself to no avail. Executing the query in Query Analyzer works. Any assistance would be greatly appreciated.

Dan

View 6 Replies View Related

Having Issues Passing Parameter Into SQL Execute Task

Oct 12, 2007

Hi, this might be a simple one, but I have been stuck on it for days. I am just getting into SSIS and have been muddling through it for the rest of this package but I am stuck on this. I am using this SQL Execute Task to run some lookup queries and then call the sp_send_dbmail stored procedure. I have this placed in a For Each loop container. I am using a SELECT DISTINCT Branch FROM table1 into an Object parameter, and passing that into the loop container. I am then using a Input Parameter into this SQL Execute Task of type String. I have run a Script task right before this step to ensure that the variable is populated and correct. Any assistance would be greatly appreciated!

Here is the SQL Execute Task :

DECLARE @SQL varchar(2400), @emaillist varchar(200),
@branchMgrEmail varchar(100), @officeMgrEmail varchar(100),
@branchMgrEmpNo varchar(5), @officeMgrEmpNo varchar(5), @subjectline varchar (100),
@Today varchar(10), @BranchNumber varchar(2)
SET @BranchNumber = ?
SET @Today = convert(char(8),getdate(),1)
SET @SQL = 'SELECT rtrim(CONVERT(char(10), PostedDate, 101)) AS Posted_Date,
CAST(Branch AS CHAR(2)) AS Branch,
CAST(Department AS CHAR(2)) AS Department,
CAST(InvoiceNumber AS CHAR(7)) AS Invoice_Number
FROM onbase.dbo.MHC_IncompleteRepairOrders
WHERE Branch = ' + @BranchNumber +
'AND HardCardCount = 0
AND WorkAuthCount = 0
AND QualityControlCount = 0
AND MiscDocsCount = 0'
SET @subjectline = @Today + ' - Repair Order Validation Notification for Branch #' + @BranchNumber
SET @branchMgrEmpNo = (SELECT branchempno FROM onbase.dbo.BranchMaster WHERE Branch = @BranchNumber)
SET @officeMgrEmpNo = (SELECT officeempno FROM onbase.dbo.BranchMaster WHERE Branch = @BranchNumber)
SET @branchMgrEmail = (SELECT empemailaddress FROM onbase.dbo.ActiveDirectory WHERE CAST(empno AS integer) = @branchMgrEmpNo)
SET @officeMgrEmail = (SELECT empemailaddress FROM onbase.dbo.ActiveDirectory WHERE CAST(empno AS integer) = @officeMgrEmpNo)
SET @emaillist = @branchMgrEmail + '; ' + @officeMgrEmail
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'email@email.com',
--@recipients = @emaillist,
--@copy_recipients = 'email@email,
@attach_query_result_as_file = 0,
@subject = @subjectline,
@body = 'This email contains a list of Stuff

',
@query = @SQL,
@query_result_header = 1,
@query_result_separator = '|',
@query_result_width = 150,
@exclude_query_output = 1,
@profile_name = 'MAIL'
END



This is a copy of the ERROR message that I am receiving. Any suggestions?


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.

Task failed: Send email to Branch Mgr and Office Mgr

View 11 Replies View Related

Problem With Package.Execute Passing Variables

Dec 20, 2006

I am having a problem with passing variables into my SSIS package from C#. The variable names match ("Variable1, ...), however they do not seem to be assigned the proper values once the package is executed. The package does run and returns a FALURE notice saying there is a problem with my expressions.

When I added a new data flow, derived all the variables into columns and wrote their values to a flat file I noticed that the values still contain my default values from the SSIS package itself as though nothing was passed in from C#. I am hoping that it is a simple configuration/user error.

Any ideas?



---- C# ----

Reference to Microsoft.SQLServer.ManagedDTS

using Microsoft.SqlServer.Dts.Runtime;

Application DTSApp = new Application();
Package DTSPack = DTSApp.LoadPackage("d:\SSISPackages\Package.dtsx", null);
DTSPack.Variables.Add("Variable1", true, "", var1.ToString());
DTSPack.Variables.Add("Variable2", true, "", var2);
DTSPack.Variables.Add("Variable3", true, "", 100);
DTSPack.Variables.Add("Variable4", true, "", var4.ToString());
DTSExecResult pkgResult = DTSPack.Execute(null, DTSPack.Variables, null, null, null);

View 16 Replies View Related

Problem When Passing Parameter To Execute SQL Task

Oct 18, 2006

Hi!

I have a execute sql task to create and drop logins. I want to create/drop the ASPNET login, but I need to pass the domain using a parameter. So I mapped a parameter:

Variable name: User::serverName

Direction: Input

DataType: Varchar

Parameter Name:0

and the sql is the following:

CREATE LOGIN [?ASPNET] FROM WINDOWS

But I get the error:

Executing the query "CREATE LOGIN [?ASPNET] FROM WINDOWS failed with the following error: "Windows NT user or group '?ASPNET' not found. Check the name again.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

What am I doing wrong?



Thank you!

View 10 Replies View Related

Passing Global Variables From A Execute Package Task

Apr 28, 2004

I have a package (Package1) that is run from another package (Package2) via a Execute Package Task. I set a Global Variable called sErrorMessage in the in Package1 and would like to access that Global Variable in an ActiveX Script Task in Package2. How can I do this?

View 6 Replies View Related

Passing Parameters To SSIS Execute Process Task

Feb 20, 2008

Hi

Can anyone help me in for the following.

i want to execute a exe file with two variable parameters

Executable : C: empMyExe.exe
Parameter1 : User::Category type is string (below example A)
Parameter2 : User::Amount type is string (below example 1)

in dos it looks like this
c: empMyExe A 1

This will executes fine.

Thanks,
Madhu

View 1 Replies View Related

Passing Variables As Arguments To Execute Process Task?

Nov 9, 2007

I am running my "execute process task" in a foreach loop that uses two variables (file paths) from the recordset that feeds into it.

My executable line looks like this: C:Program FilesWinZipWZZIP.EXE ,
which runs the command line Winzip executable and my argument line looks like this: -rp @ZipArch @ZipTxt.

When I replace the variables with literal strings, the process works (only once, of course).

My Argument won't parse in the expression editor, nor does the process run when embedded in the foreach loop. What am I doing wrong? Thanks for your help.


View 12 Replies View Related

Passing Command-line Options Through To Package.Execute()

Mar 8, 2008



Hi,
I'm looking into the idea of building an enhanced version of dtexec.exe that builds in some extra logging features. My utility will execute packages using the Package.Execute() method.

Thing is, I'd still want to support all of the command-line options that dtexec supports. For example, my utility should accept "/set package.variables[myvariable].Value;myvalue" and pass it through to the executing package but I can't find a way of doing it using Package.Execute().

Am I missing something or is this just not possible?

Thanks
Jamie


[Microsoft follow-up]

View 7 Replies View Related

Passing Parameter To Kill Staement In Execute SQL Task

Oct 18, 2007



Hi,

I have an Execute SQL Task that contains the following line:

kill ?

I have a variable (Spid) that I would like to pass as a parameter.

The connection is OLEDB.

I have tried naming the parameter 0, 1 but to no avail

I have also tried:

kill @spid

and named the parameter @Spid. This also does not work.

The variable contains a value obtained from a query that returns a spid for a locked table and is type INT32.

Can I even use the kill statement in such a context?

View 4 Replies View Related

Execute SQL Task Passing Parameters To A Restore Command

Mar 22, 2007

Hi,

I'm very new to SSIS and I€™m trying to do the following in a SQL task

RESTORE DATABASE @DatabaseName FROM DISK = @Backup WITH FILE = 1, MOVE @OldMDFName TO @NewMDFPath, MOVE @OldLDFName TO @NewLDFPath, NOUNLOAD, REPLACE, STATS = 10

I'm using an OLE DB connection and I have mapped user variables to the various parameter names. Unfortunately when i test the above command it fails on must declare the scalar variable "@DatabaseName". How can i get my values to be substituted into the command?

Many thanks

Martin



View 4 Replies View Related

Reg: Executing And Passing Arguements To Exe Using SSIS Execute Process Task

Apr 22, 2008

Hi,

Can any one give me a solution how to call exe. Also, i need to pass 1 input to that exe.
I tried using Execute process task but it is not working.

My task is:

I have DFT , it generate a output file then after the output file generated i need to upload it SharePoint server.
So i developed one .exe using .net, C#. ( it is running fine when cmd line)

But i want to embbed in SSIS package.

Like :

DFT ( DataFlowTask) --------------------> OutPutFile.txt

EPT ( ExecuteProcessTask) ----------> Upload it to SharePointPortal.


Kindly give the solution ASAP.

Thanks
Senthil

View 4 Replies View Related

Passing Object Variable As Input Parameter To An Execute SQL Task Query

Mar 29, 2007

I've encountered a new problem with an SSIS Pkg where I have a seq. of Execute SQL tasks. My question are:

1) In the First Execute SQL Task, I want to store a single row result of @@identity type into a User Variable User::LoadID of What type. ( I tried using DBNull Type or Object type which works, not with any other type, it but I can't proceed to step 2 )



2) Now I want to use this User::LoadID as input parameter of What type for the next task (I tried using Numeric, Long, DB_Numeric, Decimal, Double none of there work).



Please give me solutions for the above two..



View 6 Replies View Related

SQL 2012 :: Passing Record Counts From Execute Task In SSIS To Package Variables

Mar 4, 2014

I've got a package in SSIS 2012 that has an Execute SQL task in the control flow level.

The SQL in question does an Upsert via the SQL merge statement. What I want to do, is return the count of records inserted and records updated (No deletes going on here to worry about). I'm using the output option to output the changed recs to a table variable.

I've tried returning the values as:

Select Count(*) as UpdateCount from @mergeOutput where Action = 'Update'
and
Select Count(*) as InsertCount from @mergeOutput where Action = 'Insert'

I've tried setting the resultset to both Single rowset and Full rowset, but i'm not seeing anything returned to the package variables I've set for them (intInsertcount and intUpdatecount).

View 2 Replies View Related

Integration Services :: Execute Process Task / Passing In Variables From SSIS To Powershell Script

May 15, 2015

I am using SSIS 2012 to dynamically backup stored procedures on a list of Servers and Databases.Here are the steps in my package,

1. Execute SQL Task: Captures a result set (configured to save the data set in an Object variable) with all the Servers and Databases on which stored procedures exist.

2. For each loop that is configured to get each each row(server name @[User::Server_Name] and databases name @[User::DataBase_Name]) from the object variable (@[User::Connection_Strings])and pass it to a connection manager that has an expression for servername
and database name.

2a)  Within the for each loop, i have an execute process task that is configured as

 i) Executable:  C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
 ii) Arguments:  Configured this to fetch value from an expression. The expression i am using is,'C:batch - CopyPowerShell Scripts to Backup Stored ProceduresScriptOutSPs.ps1' -$Server_Name "+ @[User::Server_Name]+ " -$Database_Name "+ @[User::DataBase_Name]
             
Note:  @[User::Server_Name] is the Servername from object variable and so is @[User::DataBase_Name] for database name . The execute task is to run a command line that triggers a powershell script with parameters. Here is the powershell script that i am using,

param([String]$Server_Name,[String]$Database_Name)
$Server = $Server_Name
$Database = $Database_Name
$savePath = "SalesDepartmentsData ScienceUsersSANDEEP PStoredProcedures_Backup"

[code]...

When i execute the script, by passing parameters from arguments, it executes successfully but nothing happens. Passing wrong arguments in the expression?

View 3 Replies View Related

Passing A Variable Value (Package Scope) To A DTS Package Embedded Into Execute DTS 2000 Task

Jul 19, 2007

Hi friends,

I have a for each loop that populates from a set of flat files into a Sql Server table, I run the Flat file Import via a dts package embedded into Execute DTS 2000 Task. I want to pass the Sourcefile Name that is fetched by the For Each Loop to assign it Global Variable in DTS. how this can be made ?



Thanks

Subhash Subramanyam

View 4 Replies View Related

Passing Execute DTS Package Result (success/failure) To Calling SSIS Package

Mar 6, 2008

I have a SSIS job, one of the last steps it performs is to execute a SQL 2000 DTS package. This has to be done as a SQL 2000 DTS package as it is performing rebuilds of SQL 2000 Analysis Services dimensions and cubes. We've found that when the DTS fails the SSIS job is happily completing showing as a success, we would prefer to know it went wrong.

As far as I'm aware SSIS merely starts the DTS off and doesn't care about it's result. I've taken a look in to turning on the logging for the execute DTS package and thought that the ExecuteDTS80PackageTaskTaskResult would give me the answer I need...but is merely written to the log not available as an event-handler. It also looks like it is not safe to put a SQL task in as the next item to go look at the SQL 2000 system tables to look at the log for the DTS package as the SSIS documentation warns that the DTS package can continue to run after the execute DTS package task has ended.

Ideally I want any error raised within the DTS package to cascade up to be an error in the SSIS job, I can then handle it appropriately. I cannot find a way to do this. Is there a way?

If not, can anyone suggest how in the remainder of the SSIS tasks I can be sure that the DTS has completed before I start any other tasks that will check for the SQL 2000 log of its execution?

View 5 Replies View Related

SqlDataSource Params ?

Jan 27, 2006

HeyLet's say I have some stored procedure that takes as a param userId and it's simple SELECT statement. I want to assign this param and value in my code how to do it ???Jarod

View 2 Replies View Related

Can DTS Take Input Params?

Oct 13, 1999

Can I pass a parameter to a DTS package?


Here is what I am trying to do: Every month we need to import a fixed format text file into one of our tables. The format and location of the file is same every month except for the name. I want to create a DTS package to import it and call this DTS package first thing in a stored procedure(after which I do some processing with this imported data). I want to create the filename in my stored procedure and then call this DTS package to import it.

I am usig DTS as the interface is so much easier and want to avoid bcp :-)

Is it possible?

Thanks in advance,
Nishi

View 1 Replies View Related

Order By Using @Params

Oct 31, 2007

Hello,
Basically I am trying to do an order by statement using variables.

I have the SQL:


IF @SortOrder = 'ASC'



BEGIN

SELECT DISTINCT D.Code as 'T1', D.CompanyName as 'T2',

S.SpendAmount as 'T3', E.SpendAmount as 'T4',

E.SpendAmount - S.SpendAmount as 'T5',

Case When S.SpendAmount > 0 Then ((E.SpendAmount - S.SpendAmount)/S.SpendAmount) * 100

When S.SpendAmount = 0 Then ((E.SpendAmount - S.SpendAmount)/1)

When E.SpendAmount > 0 Then ((E.SpendAmount - S.SpendAmount)/E.SpendAmount) * 100

When E.SpendAmount = 0 Then ((E.SpendAmount - S.SpendAmount)/1)

END as 'T6'

FROM DivisionData D,

(SELECT Code, SpendAmount FROM DivisionData WHERE Year = @StartYear and Month = @StartMonth and Division = @Division) S,

(SELECT Code, SpendAmount FROM DivisionData WHERE Year = @EndYear and Month = @EndMonth and Division = @Division) E

WHERE D.Division = @Division

AND S.Code = D.Code

AND E.Code = D.Code



END



I have the params @Crit1 @Crit2 .... to @Crit6. These parameters come from a web form and can have the values 'T1' 'T2'... to 'T6' They correspond to the field names I have put in my select statement.
What I want to do is use these params in an Order By statement, enabling the user to select how the fields are ordered.
I have tried using something along the lines of:


ORDER BY

CASE WHEN @Crit1 = 'T1'

THEN 'T1' END


This works as long as I dont use the word DISTINCT in my select statement, otherwise I get the error:

Msg 145, Level 15, State 1, Line 4

ORDER BY items must appear in the select list if SELECT DISTINCT is specified.


I do need the distinct... I was wondering if there is a simple way to get round this, or if anyone can point me in the right direction or a article/example of this?

Many thanks

Andrew Rayner

View 6 Replies View Related

Conditional Input Params To SP

Feb 2, 2004

I've got a pretty straightforward search/results suite with several possible search parameters on the search page. I've been using an inline SQL server query with logic on the results page as shown below. How do I convert this kind of conditional logic to a stored procedure?

Dim strWhere
strWhere = " WHERE dbo.""User"".UID IS NOT NULL "

If Not request.querystring("EmployerID") = "" Then
strWhere = strWhere & " AND dbo.""User"".EmployerID = '" & replace(request.querystring("EmployerID"),"'","''") & "'"
End If

If Not request.querystring("AccountNumber") = "" Then
strWhere = strWhere & " AND dbo.""User"".AccountNumber = '" & replace(request.querystring("AccountNumber"),"'","''") & "'"
End If

If Not request.querystring("LastName") = "" Then
strWhere = strWhere & " AND dbo.""User"".LastName = '" & replace(request.querystring("LastName"),"'","''") & "'"
End If

If Not request.querystring("FirstName") = "" Then
strWhere = strWhere & " AND dbo.""User"".FirstName = '" & replace(request.querystring("FirstName"),"'","''") & "'"
End If

DBConn = New OleDbConnection(ConfigurationSettings.AppSettings("ConnStr"))
DBCommand = New OleDbDataAdapter _
("SELECT dbo.""User"".*, Convert(varchar(16), dbo.""User"".DateEntered, 101) AS Created, dbo.Employer.CompanyName, dbo.AccessLevel.AccessLevel AS AccessLevelName FROM dbo.""User"" INNER Join dbo.Employer ON dbo.""User"".EmployerID = dbo.Employer.EmployerID INNER JOIN dbo.AccessLevel ON dbo.""User"".AccessLevel = dbo.AccessLevel.AccessLevelID " & strWhere & " ORDER BY " & strSortField,DBConn)

Thanks in advance?

View 3 Replies View Related

EXECuting Sp's Within Sp's (using Return Params)

Feb 1, 2005

Hi all,
To optimise certain functionality in my app I want to do a few inserts after another by executing the whole lot in one procedure. I want to use the return param from some procedures (RETURN @@IDENTITY) as input for some of the other procedures.

I am getting errors when I compile the proc:
Line 10: Incorrect syntax near the keyword "EXEC"
Same error on Line 11...

CREATE PROCEDURE addTemplateDetail
@TemplateID int,
@GroupNameID int,
@SubGroupNameID int=null,
@MethodID int,
@AnalyteID int
AS
DECLARE @TemplateGroupNameID int
DECLARE @TemplateMethodID int
SET @TemplateGroupNameID=(EXEC addTemplateGroupName @TemplateID, @GroupNameID)
SET @TemplateMethodID=(EXEC addTemplateMethod @TemplateGroupNameID, @SubGroupNameID, @MethodID)
EXEC addTemplateAnalyte(@TemplateMethodID,@AnalyteID)

I also tried adding brackets around the input params for the EXECed sp's, but that generated even more errors...
Can somebody see what I am doing wrong?
TIA.

View 1 Replies View Related

Dynamic SQL && Output Params

Feb 7, 2005

I have a long running trigger that makes calls to several tables in order to get values for a list of parameters before doing my final INSERT statement into a different table.

One of my parameters is for a local language translation of a particular word which is stored in a table. The problem is - I do not know the name of the table until runtime when I dynamically build the name as follows:


DECLARE @SQL nVarChar(200)
SET @SQL = 'SELECT @Translation = nvcLocalEventDescription FROM Monitoring.dbo.tblSignalTemplate'
+ CAST(@MonitoringCentreID AS nVarChar) + ' WHERE nvcEventDescription = "' + @EventDescription + '"'

EXECUTE Management.dbo.usp_parmsel_LocalEventDescription @SQL, @LocalEventDescription OUTPUT


If there is a MonitoringCentreID of 1234, then there will be a table named tblSignalTemplate1234 - which will contain a nvcLocalEventDescription field containing the value that I am after. Here is the code for the stored procedure...


CREATE PROCEDURE [dbo].[usp_parmsel_LocalEventDescription]
@strSQL nVarchar(150),
@Translation nVarChar(100) OUTPUT
AS
EXECUTE sp_executesql @strSQL
GO


The error I get is "Must declare the variable '@Translation'" - which has thrown me a little as it declared on the 3rd line of the stored proc.

Anyone got any ideas where I am going wrong, or as usual, is there a simpler way ?

Steve.

View 2 Replies View Related

Displaying Params In Report

Feb 6, 2007

Hi... I am trying to display a parameter in my report.. the parameter can have up to 5 chocies... if all 5 are checked I want to display all 5..

I know how to trick it and use: Parameters!Country.Value(0)&Parameters!Country.Value(1) etc

Is there a way to do this that I dont have to have from (0) to (5)..

another thing... when you only choose 2 of the 5 params the rest show errors.. (#Error)

Thanks for help... and Happy Reporting !!

View 1 Replies View Related

Array Params To Stored Procedures?

Jul 13, 2004

This is not obvious to me...

As far as i can tell, you cannot pass an array (or structured) parameter to a stored procedure...

Ok, this means when you have to store data for an item and its sub-items (e.g. a product and its - say- version specific infos) you cannot code all the logic into a single procedure. You need to code it into your DAL, where you first insert then loop to sub-insert...

Is this correct?
Is there any other way to approach the problem?

Thanks a lot. -julio

View 3 Replies View Related

Please Help! Cannot See Values In Output Params From SQL Server 2000 Using C# / ASP.NET

May 26, 2004

Hi,

I've got the following C# function to add a customer record to the database. The record gets added without any problems but the OUTPUT PARAMETER (Parameter[10]) is always NULL and I can't see why. I'm also using the Microsoft Data Application Block.

Here's the C# function:

public void SaveCustomer(int customerId,string customerName,string address1,
string address2,
string town,
string county,
string postcode,
string webSiteAddress,
string mainTelNo,
string mainFaxNo)

{
try
{
SqlParameter[] parameters = DA.SqlHelperParameterCache.GetSpParameterSet(this.ConnectionString,"UpdateCustomer");
parameters[0].Value = customerId;
parameters[1].Value = customerName;
parameters[2].Value = address1;
parameters[3].Value = address2;
parameters[4].Value = town;
parameters[5].Value = county;
parameters[6].Value = postcode;
parameters[7].Value = webSiteAddress;
parameters[8].Value = mainTelNo;
parameters[9].Value = mainFaxNo;
parameters[10].Direction = ParameterDirection.Output;

int RetVal = DA.SqlHelper.ExecuteNonQuery(this.Connection,"UpdateCustomer",parameters);

if (RetVal > 0)
{
int Key = Convert.ToInt32(parameters[10].Value.ToString());
}

}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString(), ex);
}

}


And here's the SQL Server 2000 Stored Procedure:


CREATE PROCEDURE UpdateCustomer

@CustomerId int,
@CustomerName varchar(100),
@Address1 varchar(50),
@Address2 varchar(50),
@Town varchar(30),
@County varchar(30),
@PostCode varchar(10),
@WebSite varchar(50),
@MainTelNo varchar(15),
@MainFaxNo varchar(15),
@ReturnValue int OUTPUT

AS

IF @CustomerId = 0
BEGIN
INSERT INTO Customer
(CustomerName, Address1, Address2, Town, County, Postcode, WebSite, MainTelNo, MainFaxNo)
VALUES(@CustomerName, @Address1, @Address2, @Town, @County, @Postcode, @WebSite, @MainTelNo, @MainFaxNo)

IF @@ERROR = 0
BEGIN
SELECT @ReturnValue = @@IDENTITY
END
ELSE
BEGIN
SELECT @ReturnValue = -1
END

END
ELSE
BEGIN
UPDATE Customer
SETCustomerName = @CustomerName,
Address1 = @Address1,
Address2 = @Address2,
Town = @Town,
County = @County,
Postcode = @Postcode,
WebSite = @WebSite,
MainTelNo = @MainTelNo,
MainFaxNo = @MainFaxNo
WHERECustomerId = @CustomerId

IF @@ERROR = 0
BEGIN
SELECT @ReturnValue = @CustomerId
END
ELSE
BEGIN
SELECT @ReturnValue = -1
END
END



Any help would be appreciated as it's starting to drive me mad now!!

View 7 Replies View Related

Getting Data (rows) And Output Params From A Query

May 15, 2005

I have a stored procedure that I use to return Purchase Orders from our PO system. It returns the data rows for PO's that match the criteria passed in (including the page to show etc.) + it returns two output params, Number of rows and Number of Pages.
Using query analyzer I can confirm the query works exactly as we want. I cannot however seem to get the data out to our ASP.net app.
Here is a function that I use in one of my classes:
<code>
Function fnListPOsByCoordinatorIDPaged(ByVal strCoordinatorID As String, ByVal intPOStatusID As Int16, _
ByVal intUserTypeID As Int16, ByVal intArchived As Int16, _ByVal intPageNum As Int32, ByVal intPerPage As Int32, _ByVal strConn As String) As SqlClient.SqlDataReader
Dim dr As SqlClient.SqlDataReader
SqlConnection1.ConnectionString = strConn
prListPOByCoordinatorPaged.Parameters("@CoordinatorID").Value = strCoordinatorIDprListPOByCoordinatorPaged.Parameters("@POStatusID").Value = intPOStatusIDprListPOByCoordinatorPaged.Parameters("@UserTypeID").Value = intUserTypeIDprListPOByCoordinatorPaged.Parameters("@Archived").Value = intArchivedprListPOByCoordinatorPaged.Parameters("@PageNum").Value = intPageNumprListPOByCoordinatorPaged.Parameters("@PerPage").Value = intPerPage
SqlConnection1.Open()dr = prListPOByCoordinatorPaged.ExecuteReader(CommandBehavior.CloseConnection)
Me.Pages = prListPOByCoordinatorPaged.Parameters("@Pages").ValueMe.Rows = prListPOByCoordinatorPaged.Parameters("@Rows").Value
If Me.Rows / intPerPage > Me.Pages Then   Me.Pages = Me.Pages + 1End If
Return dr
prListPOByCoordinatorPaged.Dispose()SqlConnection1.Close()SqlConnection1.Dispose()
End Function
</code>
It does not crash, it returns my data reader with the correct records. Unfortunately my property values are returned as 0. They should have values.
Anyone know how to do this?
Thanks.

View 1 Replies View Related







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