Click to See Complete Forum and Search --> : SQL Stored Procedures


June 3rd, 1999, 08:49 AM
All I want to do is hard code two parameters to a stored procedure. I have tried
{call MyProc ('StringParam') , 56}
{call MyProc 'StringParam' , 56}
{call MyProc ('StringParam') , (56)}
{call MyProc 'StringParam' , 56}
{call MyProc 'StringParam' 56}
{call MyProc ('StringParam') (56)}

and nothing works - I get 'syntax error or access violation when opening the record set. Hard coding a single parameter stored procedure works a treat :-

{call MyProc ('StringParam')}

Please help. Could you also mail me back on Malcolm@Utopia.Uk.Com as I am still waiting my login password to this forum. Thanks.

igor
June 7th, 1999, 10:29 AM
Try to format parameters like you would do with printf function
int i=56;
ExecuteSQL({call MyProc("MyString %d",i});

yuansj
June 7th, 1999, 07:50 PM
Hi,
I am not sure about the format of the parameters in your codes, while it is possible to send parameters into a stored procedure using SQL API.
Hope this will help.



SQLRETURN retcode;

TIMESTAMP_STRUCT dsDynamicCurDate;
SQLINTEGER
siIntRet;

SQLINTEGER
cbDynamicCurDate = 0,
cbIntRet = 0;

retcode = SQLPrepare(g_hstmt, (SQLCHAR*)
"{call ? := guanj.PkgMorrowPlan.Plan2Dynamic( ? )}",
SQL_NTS);


if (retcode == SQL_SUCCESS)
{

SQLBindParameter(g_hstmt, 1, SQL_PARAM_OUTPUT, SQL_C_SLONG,
SQL_INTEGER, 0, 0, &siIntRet, 0, &cbIntRet);

SQLBindParameter(g_hstmt, 2, SQL_PARAM_INPUT, SQL_C_TIMESTAMP,
SQL_TIMESTAMP, 0, 0, &dsDynamicCurDate, 0, &cbDynamicCurDate);


COleDateTime dateTest = COleDateTime::GetCurrentTime();

dsDynamicCurDate.year = dateTest.GetYear();
dsDynamicCurDate.month = dateTest.GetMonth();
dsDynamicCurDate.hour = dateTest.GetHour();
dsDynamicCurDate.day = dateTest.GetDay();
dsDynamicCurDate.minute = dateTest.GetMinute();
dsDynamicCurDate.second = 0;
dsDynamicCurDate.fraction = 0;

retcode = SQLExecute(g_hstmt);

if (retcode != SQL_SUCCESS)
AfxMessageBox("Failed");
}

Mike Borozdin
June 8th, 1999, 12:32 PM
If you are working with SQL Server and MFC CDatabase classes try this:

db.ExecuteSQL("EXEC YourProc 'stringarg', intarg");

with "EXEC..."
you should be able to finish it up with a call identical to the ones you type in iSQL.

Software Engineer @ Interlinq Corp / Servicing Section