C/S problem. About Delphi and SQL Server

silas 2000-03-01 07:22:00
Could you like to help me to solve the problem of SQL Server and Delphi.
Thanks first!

In SQL Server 7.0, I made a StoreProc like below:
Select title=Convert(char(30)),title),price
from titles
where type='popular_comp'
Compute AVG(price),Sum(price)

the SQL Server returns like below:
titles price
----------------------------------------------------
but is it user friendly? 22.95
secrets of silicon valley 20.00
net etiquette (null)

avg
=====================
21.48
sum
=====================
21.48

I want to know how get the AVG(price) and SUM(price) in Delphi.
I know the StoreProcdure control how to get the select command by get the single value (through storproc1.param() and DBgrid).
But both single value and result set I could not solve it

thank again!
but I only know




...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
LittleStar 2000-03-02
  • 打赏
  • 举报
回复
在SQL SERVER中定义存贮过程时将要返回的记录集在最后用select @param。在delphi中就可以使用TQuery.
create proc Myprocedure(@param char(20))
as
begin
select @param=firstname from authors
select @param
end
TQuery这样引用:
query1.sql.clear;
query1.sql.add('exec Myprocedure');
query1.active:=true;
之后对TQuery的操作与一般的TDATASET没什么不同!
CJ 2000-03-01
  • 打赏
  • 举报
回复
storedproc1.open;
xxx := storedproc1.fields[0].asinteger
hawkview 2000-03-01
  • 打赏
  • 举报
回复
对于用存储过程返回两个或两个值的情况可如下解决
用一Query控件其SQL语言为'select * from 存储过程名',即可返回结果集。


5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧