从存储过程输出数据 [英] Outputting Data From Stored Procedure

查看:80
本文介绍了从存储过程输出数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我通常是一个vb程序员,我用来引用多个记录

从在sql数据库上执行的查询返回并且我试图移动

我的软件的一些功能进入sql存储过程。到目前为止,我已经能够相对轻松地移动函数,但我不确定如何从一个sql存储过程输出多个值。我的意思是

示例其中一个存储过程可能会占用您的用户名并返回其中一个表的记录中单个字段的

内容,但是我如果可能的话,我会希望能够从两个记录中返回单个字段的内容。
。在VB下我用来引用记录集

后用(1)来引用查询中的相应记录。我想b / b
是否有办法在可能的情况下用存储的

程序做类似的事情?


谢谢你任何帮助

Hi All

Im generally a vb programmer and am used to referencing multiple records
returned from a query performed on an sql database and im trying to move
some functions of my software into sql stored procedures. So far ive been
able to move the functions relatively easily but im unsure about how to
output multiple values from an sql stored procedure. By this i mean for
example one of the stored procedures may take your username and return the
contents of a single field in a record of one of the tables, but i would
like to be able to return for arguement sake the contents of a single field
from two records if possible. Under VB im used to referencing the recordset
with a (1) after it to reference the corresponding record from the query. I
was wondering if there is a way to do something similar to this with stored
procedures if possible ?

Thanks for any help

推荐答案

Jarrod Morrison(ja**** *@ihug.com.au)写道:
Jarrod Morrison (ja*****@ihug.com.au) writes:
Im通常是一个vb程序员,我用来引用从sql数据库执行的查询返回的多个记录,我试图将我的软件的一些功能移动到sql存储过程中。到目前为止,我已经能够相对容易地移动函数,但我不确定如何从sql存储过程输出多个值。通过这个我的意思,例如,其中一个存储过程可能会使用您的用户名和
返回其中一个表的记录中的单个字段的内容,
但我想成为如果可能的话,能够从两个记录中返回单个字段的内容。在VB下我习惯用一个(1)引用记录集后,从查询中引用相应的记录。我想知道是否有办法用存储过程做类似的事情,如果可能的话?
Im generally a vb programmer and am used to referencing multiple records
returned from a query performed on an sql database and im trying to move
some functions of my software into sql stored procedures. So far ive
been able to move the functions relatively easily but im unsure about
how to output multiple values from an sql stored procedure. By this i
mean for example one of the stored procedures may take your username and
return the contents of a single field in a record of one of the tables,
but i would like to be able to return for arguement sake the contents of
a single field from two records if possible. Under VB im used to
referencing the recordset with a (1) after it to reference the
corresponding record from the query. I was wondering if there is a way
to do something similar to this with stored procedures if possible ?




不幸的是,没有一个例子,我发现很难获得一个明确的

了解你正在做什么。


然而,一般警告:SQL是一种非常不同的语言

比基本不同的心态。通过

行将VB转换为SQL行,可能并不总是最好的方法。


因为我不知道你在做什么,这个链接可能完全无关紧要。但也许它可以解决你想要做的事情。

http://www.algonet.se/~sommar/share_data.html


-

Erland Sommarskog, SQL Server MVP, so****@algonet.se


联机丛书SQL Server SP3
http:// www.microsoft.com/sql/techinf...2000/books.asp



Unfortunately, without an example, I find it difficult to get a clear
understanding of what you are doing.

However, a general word of caution: SQL is a very different language
than Basic with different mindsets. Translating VB into SQL line by
line, may not always be the best approach.

Since I don''t know what you are doing, this link may be completely
irrelevant. But maybe it addresses something of what you are trying to
do: http://www.algonet.se/~sommar/share_data.html.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


嗨Erland


谢谢你的链接,它对我有点帮助,但我想我会给你一个直接的例子,看看我能做些什么来看看你是否可以给我

任何关于我能做什么的进一步指示。在我的存储过程中,我将执行查询并将结果存储在过程中的临时表中。一个

表中的内容如下:


PrinterPath名称优先级


\ \Server1 \ Printer1打印机1 1

\\Server2 \Printer2打印机2 2


我想要做的只是输出第一列数据从

过程到我的vb客户端程序(IE:\\Server1 \Printer1和

\\Server2 \Printer2)。显然这是一个基本的例子,

数据和记录的数量将一直在变化。首先,我只想输出
输出第一列,但如果可能的话,我也希望

尽可能多列。目前在我的其他存储的

程序中,我只是在程序开始时定义一个变量

作为输出,并在程序结束前为其赋值。我希望

有一种简单的方法可以以类似的方式从存储过程输出多个值。


谢谢你所有你的帮助


" Erland Sommarskog" <所以**** @ algonet.se>在消息中写道

news:Xn ********************* @ 127.0.0.1 ...
Hi Erland

Thankyou for the link, it sort of helped me a little bit, but I thought I
would give you a direct example of what I am doing to see if you can give me
any further pointers on what I can do. In my stored procedure I will execute
a query and store the results in a temporary table in the procedure. An
Example of what will be in the table is as follows:

PrinterPath Name Priority

\\Server1\Printer1 Printer 1 1
\\Server2\Printer2 Printer 2 2

What I want to do is to output only the first columns data from the
procedure to my vb client program (IE: \\Server1\Printer1 and
\\Server2\Printer2). Obviously this is a basic example and the amount of
data and records will change all the time. To begin with I only want to
output the first column, but if possible down the track I would also like to
do multiple columns if it is possible. At the moment in my other stored
procedures I am just defining a variable at the beginning of the procedure
as output and assigning a value to it before the procedure ends. I am hoping
there is an easy way to output multiple values from the stored procedure in
a similar fashion.

Thanks for all your help

"Erland Sommarskog" <so****@algonet.se> wrote in message
news:Xn*********************@127.0.0.1...
不幸的是,如果没有一个例子,我发现很难清楚地了解你在做什么。

然而,一般的警告:SQL是一个非常不同的语言比基本不同的心态。通过
行将VB转换为SQL行可能并不总是最好的方法。

由于我不知道你在做什么,这个链接可能完全无关紧要。但也许它可以解决您尝试做的事情: http://www.algonet.se/~sommar/share_data.html

- Erland Sommarskog,SQL Server MVP, so **** @ algonet.se

SQL Server SP3的在线书籍
http://www.microsoft.com/sql/techinf...2000/books。 asp
Unfortunately, without an example, I find it difficult to get a clear
understanding of what you are doing.

However, a general word of caution: SQL is a very different language
than Basic with different mindsets. Translating VB into SQL line by
line, may not always be the best approach.

Since I don''t know what you are doing, this link may be completely
irrelevant. But maybe it addresses something of what you are trying to
do: http://www.algonet.se/~sommar/share_data.html.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp



Jarrod Morrison(ja*****@ihug.com.au)写道:
Jarrod Morrison (ja*****@ihug.com.au) writes:
表中的内容示例如下:

PrinterPath名称优先级

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Server2 \Printer2 Printer 2 2

我想要做的只是输出第一列数据从
过程到我的vb客户端程序(IE:\\Server1 \Printer1和
\\Server2 \Printer2)。显然这是一个基本的例子,数据和记录的数量将一直在变化。首先,我只想输出第一列,但如果可能的话,如果可能的话,我也会想要多列。
Example of what will be in the table is as follows:

PrinterPath Name Priority

\\Server1\Printer1 Printer 1 1
\\Server2\Printer2 Printer 2 2

What I want to do is to output only the first columns data from the
procedure to my vb client program (IE: \\Server1\Printer1 and
\\Server2\Printer2). Obviously this is a basic example and the amount of
data and records will change all the time. To begin with I only want to
output the first column, but if possible down the track I would also
like to do multiple columns if it is possible.



SELECT PrinterPath FROM tbl WHERE ...


SELECT PrinterPath,Name FROM tbl WHERE ...


然后在VB中你收到记录集中的值。


-

Erland Sommarskog,SQL Server MVP, so **** @ algonet.se


SQL Server SP3联机丛书
http://www.microsoft.com/sql/techinf...2000/books.asp



SELECT PrinterPath FROM tbl WHERE ...

SELECT PrinterPath, Name FROM tbl WHERE ...

Then in VB you receive the values in a recordset.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


这篇关于从存储过程输出数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆