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、一起显示。

解决方案 »

  1.   

    content字段是字符型吧?
    看上去又是一个字符串合并的问题,搜索一下吧,一大把。
      

  2.   

    select a.id,a.datetime,b.content from a ,b where datetime='2008-6-26' and a.id=b.id
      

  3.   

    select a.id,a.datetime,b.content from a ,b where datetime='2008-6-26' and a.id=b.newid
      

  4.   

    select a.*,b.* from a inner join b on a.id=B.newid where datetime='2008-6-26'
      

  5.   

    类似与这样的效果~
    select a.id,a.datetime,b.content from a 
    left join b on a.id=b.id 
    where datetime='2008-6-26'
      

  6.   

    能不能让a标的记录不重复,b表的所有符合a.id=b.id条件的b表记录叠加成一条记录呢?
      

  7.   


    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
      

  8.   

    select id,datetime from a where datetime='2008-6-26'
    union all
    select 1,content=(select content from b where  [newid]=a.id ) from a where datetime='2008-6-26'
      

  9.   

    1.创建函数GetContentCREATE  function GetContent(@Id int)
    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'