RE: SQL for SP
From: Alejandro Mesa (AlejandroMesa_at_discussions.microsoft.com)
Date: 10/01/04
- Next message: seeker53: "Re: triggers"
- Previous message: Adam Machanic: "Re: Assign variable in Case statement"
- In reply to: Alejandro Mesa: "RE: SQL for SP"
- Next in thread: Jeff Johnson [MVP: VB]: "Re: SQL for SP"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 1 Oct 2004 08:09:05 -0700
But you can access this value with a recordset object (ADO). You will be
incurring in extra work because SQL Server has to parse and create an
execution plan for the statement every time you use it. Also, the interface
(ADO) has to create a recordset because you are returning the value using a
SELECT statement.
dim oRst as adodb.recordset
dim oConn as adodb.connection
set oConn = new adodb.connection
' set connection properties and open it
...
strSQL = "INSERT INTO dbo.CompanyData (CompanyName, Address1)
VALUES (" & strCompanyName & ", " & strAddress1 & ") "
strSQL = strSQL & "SELECT SCOPE_IDENTITY() as newIdent"
set oRst = oConn.execute strSQL
...
Here are a couple of articles where to read about ADO Best Practices.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlmag01/html/bestprac.asp
http://www.winnetmag.com/SQLServer/Article/ArticleID/16272/SQLServer_16272.html
AMB
"Alejandro Mesa" wrote:
> That is the beauty of using a sp, you have a return value and output
> parameters. This functionality is not available when using parameterized
> queries on ADO or ADO.NET.
>
>
>
> AMB
>
> "Vlad" wrote:
>
> > I have SP in SQL Server:
> > CREATE PROCEDURE Admin_BuySellCompanyInsertUpdate
> > @CompanyName varchar(50)
> > @Address1 varchar(50),
> > @NewBuySellCompanyID int output
> >
> >
> > AS
> > INSERT INTO dbo.CompanyData (CompanyName, Address1)
> > VALUES (@CompanyName, @Address1)
> > SELECT @NewBuySellCompanyID = SCOPE_IDENTITY()
> > GO
> >
> > Instead of using this SP for Command object with CommandType
> > =adCmdStoredProc in VB6 I would like to have
> > Command object with CommandType = adCmdText
> >
> > I tried to write SQL statement for this case with no success.
> > My last attempt was:
> > strSQL = "DECLARE @NewBuySellCompanyID int OUTPUT "
> > strSQL = "INSERT INTO dbo.CompanyData (CompanyName, Address1)
> > VALUES (" & strCompanyName & ", " & strAddress1 & ") "
> > strSQL = strSQL & "SELECT @NewBuySellCompanyID = SCOPE_IDENTITY()"
> >
> > Set parTemp = New ADODB.Parameter
> > parTemp.Direction = adParamOutput
> > parTemp.Type = adInteger
> > parTemp.Name = "@NewBuySellCompanyID"
> >
> > Set cndTemp = New ADODB.Command
> > cndTemp.ActiveConnection = objConn
> > cndTemp.CommandType = adCmdText
> > cndTemp.CommandText = strSQL
> > cndTemp.Parameters.Append parTemp
> > cndTemp.Execute
> >
> > I'm getting an error
> > Maybe it's not possible at all? Ofcourse it's better to run SP, but I have
> > much more experience with VB than with SQL Server and have more control on
> > pretty complex routine which includes this insert in VB.
> >
> > Any help please
> > Thank you
> > Vlad
> >
> >
> >
> >
- Next message: seeker53: "Re: triggers"
- Previous message: Adam Machanic: "Re: Assign variable in Case statement"
- In reply to: Alejandro Mesa: "RE: SQL for SP"
- Next in thread: Jeff Johnson [MVP: VB]: "Re: SQL for SP"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|