Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rnoJoe
Starting Member
4 Posts |
Posted - 2007-03-12 : 18:17:49
|
Hi,I have a stored procedure that move data from one table to another. I would like the stored procedure to pass a value back to the access database application that called it so the user can know that the data was moved successfully. Any help would be greatly appreciatedcode in Access DB: StrSPEmps = "spEmpUpdate" Set Db = DBEngine.Workspaces(0).OpenDatabase("", False, False, "ODBC;dsn=DivisionSQLDb;uid=empdata;pwd=empdata") Db.Execute StrSPEmps, dbSQLPassThrough Set Rs = Db.OpenRecordset(StrSPEmps, dbOpenSnapshot, dbSQLPassThrough) StrFlag = Rs!FlagStored Procedure CodeCREATE PROCEDURE spEmpUpdate (@Flag char(2))ASIf EXISTS (Select * from TableA,TableB where (TabelA.ID = TableB.ID) Set @Flag= 'T'ElseInsert INTO TableA Select * from TableB set @Flag = 'F'GOI would like the T or F to be sent back to the acces DB so the user knows if the record was already in TableA or if the records was moved successfullyThank youJoe |
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2007-03-12 : 22:58:57
|
Use ADO record set to run stored procedure from access application.mk_garg |
 |
|
rnoJoe
Starting Member
4 Posts |
Posted - 2007-03-13 : 11:48:46
|
using ADO....thats what I thought I was doing. Can you take a look at the code and let me know what I am doing wrong?thank you for your help |
 |
|
JohnH
Starting Member
13 Posts |
Posted - 2007-03-13 : 15:35:39
|
I'd change the proc just a little. Do use joins and aliases. Uncomment only one of the two commented SELECT statements.ALTER PROC spEmpUpdateASINSERT TableASELECT *FROM TableBWHERE NOT EXISTS (SELECT 1 FROM TableA A JOIN TableB B ON A.ID = B.ID)-- This gives a little more than just 'T' or 'F'--SELECT @@ROWCOUNT AS 'Rows_Inserted'-- Or this gives just the minimum--SELECT CASE WHEN @@ROWCOUNT = 0 THEN 'T' ELSE 'F' END AS 'Results'Then in your Access DB code, get the 1st row of the recordset and check the value of the 1st column. I've tested the proc, but not the Access bit.John Hopkins |
 |
|
rnoJoe
Starting Member
4 Posts |
Posted - 2007-03-14 : 13:58:48
|
can anyone help with the VBA code? I cant figure out how to get that result back to my access application.thanks you John H for your help |
 |
|
michaelxvo
Starting Member
47 Posts |
Posted - 2007-03-14 : 16:04:30
|
quote: Originally posted by rnoJoe Hi,I have a stored procedure that move data from one table to another. I would like the stored procedure to pass a value back to the access database application that called it so the user can know that the data was moved successfully. Any help would be greatly appreciatedcode in Access DB: StrSPEmps = "spEmpUpdate" Set Db = DBEngine.Workspaces(0).OpenDatabase("", False, False, "ODBC;dsn=DivisionSQLDb;uid=empdata;pwd=empdata") Db.Execute StrSPEmps, dbSQLPassThrough Set Rs = Db.OpenRecordset(StrSPEmps, dbOpenSnapshot, dbSQLPassThrough) StrFlag = Rs!FlagStored Procedure CodeCREATE PROCEDURE spEmpUpdate (@Flag char(2))ASIf EXISTS (Select * from TableA,TableB where (TabelA.ID = TableB.ID) Set @Flag= 'T'ElseInsert INTO TableA Select * from TableB set @Flag = 'F'GOI would like the T or F to be sent back to the acces DB so the user knows if the record was already in TableA or if the records was moved successfullyThank youJoe
FROM SQL SERVERCREATE PROCEDURE spEmpUpdate (@Flag char(2) OUTPUT)ASIf EXISTS (Select * from TableA,TableB where (TabelA.ID = TableB.ID) Set @Flag= 'T'ElseInsert INTO TableA Select * from TableB set @Flag = 'F'GOFROM VBA CODEdim cn as new adodb.connectiondim cmd as new adodb.commanddim strFlag as stringcn.connectionstring = "Data Source=machinename;initial catalog=databasename;Trusted_connection=Yes;"cn.opencmd.ActiveConnection = cncmd.CommandText ="spEmpUpdate"cmd.CommandType=adcmdStoredProccmd.parameters.append cmd.createparameter("@Flag",AdChar,AdParamOutput,2)cmd.executestrFlag = cmd(0)msgbox strFlag |
 |
|
|
|
|
|
|