Re: vbscript logon script getting return data from sql sp
- From: "terryteppo" <terryteppo@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 18 May 2005 19:29:16 -0700
SCOPE_IDENTITY
is the same thing as @@IDENTITY
but for the currect session / table
example table with trigger
insert data
trigger fires and inserts data in other table
@@IDENTITY says number for second insert
SCOPE_IDENTITY says data for the first insert
"Richard Mueller [MVP]" wrote:
>
> > '---------------------------
> > set CmdSP = CreateObject("ADODB.Command")
> > CmdSP.ActiveConnection = "Provider=SQLOLEDB;Data Source=servername;Initial
> > Catalog=database;Integrated Security=SSPI;Persist Security Info=False"'
> > cmdstr= "allinone "&chr(34)& v1 &
> >
> chr(34)&","&chr(34)&v2&chr(34)&","&chr(34)&v3&chr(34)&","&chr(34)&v4&chr(34)
> &","&chr(34)&v5&chr(34)&","&chr(34)&v6&chr(34)&","&chr(34)&v7&chr(34)&","&ch
> r(34)&v8&chr(34)&","&chr(34)&v9&chr(34)&","&chr(34)&v10&chr(34)&","&chr(34)&
> v11&chr(34)&","&chr(34)&v12&chr(34)&","&chr(34)&v13&chr(34)&","&chr(34)&v14&
> chr(34)&","&chr(34)&v15&chr(34)&","&chr(34)&v16&chr(34)&","&chr(34)&v17&chr(
> 34)&","&chr(34)&v18&chr(34)&","&chr(34)&v19&chr(34)&","&chr(34)&v8&chr(34)&"
> ,"&chr(34)&v9&chr(34)
> > 'Wscript.Echo cmdstr
> > CmdSP.CommandText = "spname "&chr(34)& v1 &
> >
> chr(34)&","&chr(34)&v2&chr(34)&","&chr(34)&v3&chr(34)&","&chr(34)&v4&chr(34)
> &","&chr(34)&v5&chr(34)&","&chr(34)&v6&chr(34)&","&chr(34)&v7&chr(34)&","&ch
> r(34)&v10&chr(34)&","&chr(34)&v11&chr(34)&","&chr(34)&v12&chr(34)&","&chr(34
> )&v13&chr(34)&","&chr(34)&v14&chr(34)&","&chr(34)&v15&chr(34)&","&chr(34)&v1
> 6&chr(34)&","&chr(34)&v17&chr(34)&","&chr(34)&v18&chr(34)&","&chr(34)&v19&ch
> r(34)&","&chr(34)&v8&chr(34)&","&chr(34)&v9&chr(34)
> > ' CmdSP.CommandType = adCmdSPStoredProc
> > CmdSP.Execute()
> > Set CmdSP = Nothing
> > cmdsp.close
>
> Hi,
>
> One way to retrieve values from a stored procedure is with a Recordset
> object. I have used code similar to:
>
> Set adoCommand = CreateObject("ADODB.Command")
> adoCommand.ActiveConnection = "xxx"
> adoCommand.CommandType = adCmdStoredProc
> adoCommand.CommandText = "MyProcName"
> Set adoRecordset = adoCommand.Execute
>
> Do Until adoRecordset.EOF
> strValue = adoRecordset.Fields(0).Value
> adoRecordset.MoveNext
> Loop
> adoRecordset.Close
>
> Specifics depend on the stored procedure. adCmdStoredProc must be defined in
> VBScript.
>
> I have also seen the Parameters method of the Command object used. Again,
> the stored procedure must define the return value, but the value would be
> retrieved with code similar to:
>
> adoCommand.Execute
> strValue = adoCommand.Parameters("@intID").Value
>
> I have to check what SCOPE_IDENTITY is, but if it is the autoincrement
> feature, you can use the @@IDENTITY function to retrieve the ID value
> assigned (assuming the stored procedure added a row to a table). For
> example, I have used:
>
> adoCommand.Execute
>
> Set adoRecordset = CreateObject("ADODB.Recordset")
> adoRecordset.ActiveConnection = "xxx"
> adoRecordset.Source = "SELECT @@IDENTITY"
> adoRecordset.Open
> lngID = CLng(adoRecordset.Fields(0).Value)
>
> @@IDENTITY returns the last autoincrement ID value assigned.
> adoRecordset.Fields(0).Value returns the first (or only) field in the
> recordset. You can retrieve fields by name with
> adoRecordset.Fields("FieldName").Value. If the stored procedure returns a
> recordset with one row, then the Do Until adoRecordset.EOF loop above loops
> once. Otherwise, you will retrieve one value for every row in the recordset.
> The @@IDENTITY function always returns one row, so I did not loop, but just
> retrieve the first (and only) value.
>
> I hope this helps. You can find documentation on @@IDENTITY, the Parameters
> method of the Command object, and the Recordset object at the Microsoft
> site. Although most of my experience with the above is with VB, I've also
> done similar in VBScript.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab web site - http://www.rlmueller.net
> --
>
>
>
.
- References:
- vbscript logon script getting return data from sql sp
- From: terryteppo
- Re: vbscript logon script getting return data from sql sp
- From: Richard Mueller [MVP]
- vbscript logon script getting return data from sql sp
- Prev by Date: Ceate IPC Connection
- Next by Date: Running CACLS.exe as user
- Previous by thread: Re: vbscript logon script getting return data from sql sp
- Next by thread: Getting Error: 800A01AD
- Index(es):
Relevant Pages
|