Delphi 数据库查询问题

来源:百度知道 编辑:UC知道 时间:2024/05/28 02:05:30
表a:id code(设置为字符型还是整型?只有一位整数)
11 1
11 2
11 3
12 1
12 3
… …
现在我想通过查询一个id,将该id的所有code号显示在DBGird中code的一个格里,该怎样实现?求教!
如: 11 123
或: 12 13

用游标实现

我写的一个 存储过程
create procedure my_pro(@id varchar(50))
with encryption as
begin
declare @code varchar(50),@str varchar(1000)
declare mycursor cursor for
select code from [表a] where id=@id
set @str=''
Open mycursor
fetch mycursor into @code
while @@fetch_status=0
begin
set @str=@str+@code
fetch mycursor into @code
end
close mycursor
deallocate mycursor
select @id as 编号,@str as 代码
end

调用方法: exec my_pro '11'
请您在解决问题之后 尽快把分送到我的帐户上 谢谢

通过程序实现;
或者你的数据库是SQL Server/Oracle之类,也可以用存贮过程来实现。

直接写SQL语句实现不了