27. april 2003 - 10:15Der er
12 kommentarer og 1 løsning
TSQL - at loope igennem et recordset!?
Hejsa,
Jeg skal i et job i min MS SQL database sætte den til først at hente en tabel ved hjælp af en SELECT sætning, derefter skal dataene behandles. Mit problem er dog hvordan jeg looper igennem et recordset!?
you should be able to find help on this in Books Online Serach after recordset! I found this
Using an ADO Connection and Recordset to Check Records The following ActiveX script creates a connection to the Northwind database and the employee table and counts the number of employee records. If employee records are found in the table, the script displays the number of employees and sends a success flag back to the package. Otherwise, the script sends a failure flag. Those flags can be used to trigger other tasks. For example, the success flag can signal that the table has records and then execute a Bulk Insert task. You can use the failure flag to execute a Send Mail task informing a database administrator (DBA) that a potential problem exists.
dim myConn dim myRecordset dim iRowCount
' instantiate the ADO objects set myConn = CreateObject("ADODB.Connection") set myRecordset = CreateObject("ADODB.Recordset")
' set the connection properties to point to the Northwind database, ' using the Customers table myConn.Open = "Provider=SQLOLEDB.1;Data Source=(local); _ Initial Catalog=Northwind;user id = 'sa';password=''"
mySQLCmdText = "Select 'rowcount' = Count(*) from Customers"
myRecordset.Open mySQLCmdText, myConn
set Flds = myRecordset.Fields set iRowCount = Flds("rowcount")
If iRowCount.Value = 0 then Main = DTSTaskExecResult_Failure Else MsgBox "The number of customers is: " & iRowCount.Value Main = DTSTaskExecResult_Success End If
ehh, det er rent faktisk vb i ASP... ja, du connecter til en SQL database med det, men det der kører du fra dine ASP sider...
Ok, i dit job kan det godt være at man i VB-delen ville kunne afvikle dette, det kan jeg så ikke udelukke... Hvis det er det, kunne jeg måske have brugt dette i stedet :s Men jeg ledte nu efter det i TSQL :)
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.