1、有A、B两个数据库表,先通过查询表A的时间字段找出表A相关的ID(主键),如:select id,datetime from a where datetime='2008-6-26'(搜索出的符合条件的记录ID会不相同)
2、在搜索出表B字段newid和表A字段ID一致的字段content,然后将所有符合条件的content字段合并作为一个记录和1、一起显示。
2、在搜索出表B字段newid和表A字段ID一致的字段content,然后将所有符合条件的content字段合并作为一个记录和1、一起显示。
看上去又是一个字符串合并的问题,搜索一下吧,一大把。
select a.id,a.datetime,b.content from a
left join b on a.id=b.id
where datetime='2008-6-26'
declare my_cursor cursor scroll dynamic
for
select content from (select a.id,a.datetime,b.content from a
inner join b on a.id=b.id
where datetime='2008-6-26'
) t
open my_cursor
declare @pname as varchar(50)
declare @a as varchar(500)
set @a=''
fetch next from my_cursor into @pname
while(@@fetch_status=0)
begin
fetch next from my_cursor into @pname
set @a=@a+@pname
end
select @a
close my_cursor
union all
select 1,content=(select content from b where [newid]=a.id ) from a where datetime='2008-6-26'
returns varchar(8000)
as
declare @content varchar(8000)
set @content=''
select @content=@uploadcontent+content from b where newid=@Id
return @content
end
2.查询
select id,datetime,GetContent(id) as content from a where datetime='2008-6-26'