存储过程:
CREATE PROCEDURE liyan
@parm1 char(5),
@parm2 varchar(200)
AS
set @parm1='liyan'
set @parm2='is a chinese'
print @parm1
print (' '+@parm2)
GO
这个存储过程在查询分析器中执行的结果是:
liyan
is a chinese
问题:怎么在delphi程序中调用这个存储过程,返回执行的结果,这里关键的地方是执行 结果在存储过程中用print的,请问怎么取到?我就是要在delphi中取到:
liyan
is a chinese 就OK了,希望大家帮忙,分马上给,我在线等待,谢谢!!
CREATE PROCEDURE liyan
@parm1 char(5),
@parm2 varchar(200)
AS
set @parm1='liyan'
set @parm2='is a chinese'
print @parm1
print (' '+@parm2)
GO
这个存储过程在查询分析器中执行的结果是:
liyan
is a chinese
问题:怎么在delphi程序中调用这个存储过程,返回执行的结果,这里关键的地方是执行 结果在存储过程中用print的,请问怎么取到?我就是要在delphi中取到:
liyan
is a chinese 就OK了,希望大家帮忙,分马上给,我在线等待,谢谢!!
解决方案 »
- dbgrid嵌入checkbox控件
- 高手请指点。高分!
- 找到句柄之后为什么用WM_SETTEXT不能改变RICHEDIT的Caption。
- 高手,救命!
- 我想编一个adsl拨号的程序,谁能够给我些资料重分感谢!
- 打开文件为什么出错?
- 急救delphi 读取泰文txt文件乱码问题
- webservice程序脱离web服务器直接执行
- :◆◇◆◇◆◇对CSDN各网友严重警告◇◆◇◆◇◆--------------Delphi版块
- 有关窗口函数??
- 谁能给出TList、TCollection、TStack、TBucketList、TQueue、TOrderedList的例子
- 关于动态创建和释放控件的问题
@parm1 char(5),
@parm2 varchar(200)
AS
set @parm1='liyan'
set @parm2='is a chinese'
Select @parm1 + Chr(13) + ' '+@parm2 as Field1
GOdelphi中用query ,设置sql 为 exec liyan '111','xxxx' ,返回的记录集 是 field1 这个字段的内容;
一般要麼用 output 參數, 要麼用 select 來返回
不好意思!!
我就是要得到这个结果,并不是能用一个传出变量解决得了问题的!!谢谢!!
declare @tmpStr varchar(4000)这样不行?带回车的string 给TStrings 后会自动分行;或者你建立临时表,把每行信息写进去,最后select 它,drop 它;甚至你可以用动态sql ,或者是返回TABLE类型的数据。
严重度为 11 或高于 11 的 sysmessages 中的错误。
严重度为 11 或高于 11 的任意 RAISERROR 语句。 。消息
PRINT 语句的输出。
几个 DBCC 语句的输出。
严重度为 10 或低于 10 的 sysmessages 中的错误。
严重度为 10 或低于 10 的任意 RAISERROR 语句。
如何处理 ODBC 错误 (ODBC)
可以使用两个 ODBC 函数调用来检索 ODBC 信息:SQLGetDiagRec 和 SQLGetDiagField。若要获得 SQLState、pfNative 和 ErrorMessage 诊断字段中与 ODBC 有关的主要信息,请调用 SQLGetDiagRec,直到它返回 SQL_NO_DATA 为止。可对每个诊断记录调用 SQLGetDiagField 以检索个别字段。所有驱动程序专用字段都必须用 SQLGetDiagField 检索。SQLGetDiagRec 和 SQLGetDiagField 由 ODBC 驱动程序管理器而不是个别的驱动程序来处理。ODBC 驱动程序管理器在连接成功建立之前,不高速缓存驱动程序专用诊断字段。在连接成功建立之前无法对驱动程序专用诊断字段调用 SQLGetDiagField。这还包括 ODBC 连接命令,即便它们返回 SQL_SUCCESS_WITH_INFO。驱动程序专用诊断字段在下一个 ODBC 函数调用之前不可用。
Using PRINT and RAISERROR Statements
Transact-SQL PRINT and RAISERROR statements also return data by calling SQLGetDiagRec. PRINT statements cause the SQL statement execution to return SQL_SUCCESS_WITH_INFO, and a subsequent call to SQLGetDiagRec returns a SQLState of 01000. A RAISERROR with a severity of ten or lower behaves the same as PRINT. A RAISERROR with a severity of 11 or higher causes the execute to return SQL_ERROR, and a subsequent call to SQLGetDiagRec returns SQLState 42000. For example, the following statement returns SQL_SUCCESS_WITH_INFO:SQLExecDirect (hstmt, "PRINT 'Some message' ", SQL_NTS);Calling SQLGetDiagRec returns:szSQLState = "01000", *pfNative Error = 0,
szErrorMsg= "[Microsoft] [ODBC SQL Server Driver][SQL Server]
Some message"The following statement returns SQL_SUCCESS_WITH_INFO:SQLExecDirect (hstmt, "RAISERROR ('Sample error 1.', 10, -1)",
SQL_NTS)Calling SQLGetDiagRec returns:szSQLState = "01000", *pfNative Error = 50000,
szErrorMsg= "[Microsoft] [ODBC SQL Server Driver][SQL Server]
Sample error 1."The following statement returns SQL_ERROR:SQLExecDirect (hstmt, "RAISERROR ('Sample error 2.', 11, -1)", SQL_NTS)Calling SQLGetDiagRec returns:szSQLState = "42000", *pfNative Error = 50000,
szErrorMsg= "[Microsoft] [ODBC SQL Server Driver][SQL Server]
Sample error 2."The timing of calling SQLGetDiagRec is critical when output from PRINT or RAISERROR statements is included in a result set. The call to SQLGetDiagRec to retrieve the PRINT or RAISERROR output must be made immediately after the statement that receives SQL_ERROR or SQL_SUCCESS_WITH_INFO. This is straightforward when only a single SQL statement is executed, as in the examples above. In these cases, the call to SQLExecDirect or SQLExecute returns SQL_ERROR or SQL_SUCCESS_WITH_INFO and SQLGetDiagRec can then be called. It is less straightforward when coding loops to handle the output of a batch of SQL statements or when executing SQL Server stored procedures.In this case, SQL Server returns a result set for every SELECT statement executed in a batch or stored procedure. If the batch or procedure contains PRINT or RAISERROR statements, the output for these is interleaved with the SELECT statement result sets. If the first statement in the batch or procedure is a PRINT or RAISERROR, the SQLExecute or SQLExecDirect returns SQL_SUCCESS_WITH_INFO or SQL_ERROR, and the application needs to call SQLGetDiagRec until it returns SQL_NO_DATA to retrieve the PRINT or RAISERROR information.If the PRINT or RAISERROR statement comes after an SQL statement (such as a SELECT statement), then the PRINT or RAISERROR information is returned when SQLMoreResults positions on the result set containing the error. SQLMoreResults returns SQL_SUCCESS_WITH_INFO or SQL_ERROR depending on the severity of the message. Messages are retrieved by calling SQLGetDiagRec until it returns SQL_NO_DATA.