如何把多个表里的text字段内容和并到一个表的text字段中
数据库是sql server ,里面有多个表,每个表都有一个或多个text类型字段, 现在我希望建立一个统一的表,把原来各个表里的text字段的内容都合并到这一个表的同一个text字段里, 每次都只能保留最后一次的赋值, While Not cnKeyW.Eof Do
Begin
if not TmemoField(cnKeyW.FieldByName( '内容 ')).IsNull then
TmemoField(cnKeyW.FieldByName( '内容 ')).SaveToStream(Stream);
cnKeyW.Next;
End;
数据库是sql server ,里面有多个表,每个表都有一个或多个text类型字段, 现在我希望建立一个统一的表,把原来各个表里的text字段的内容都合并到这一个表的同一个text字段里, 每次都只能保留最后一次的赋值, While Not cnKeyW.Eof Do
Begin
if not TmemoField(cnKeyW.FieldByName( '内容 ')).IsNull then
TmemoField(cnKeyW.FieldByName( '内容 ')).SaveToStream(Stream);
cnKeyW.Next;
End;
2:建立一个关联字段,把那些text付到一个字段里面,直接利用‘+’号就OK,
而每一个单个的都没有这个问题
Cus.FieldByName('建议').Value := Cus.FieldByName('建议').Value +
cnKeyW.FieldByName('内容').Value;
Cus.Post;是你的意思吗?显示规则是,是指,内容中包括了字体,颜色等,可以用richedit 显示的
Cus.Edit;
Cus.FieldByName( '建议 ').Value := Cus.FieldByName( '建议 ').Value +
cnKeyW.FieldByName( '内容 ').Value;
Cus.Post; 实际上最后显示的是最早加入的,后加入的都没有
其次:
举例:控件AdoQuery
with AdoQuery do
Begin
*******
end;
while not adoquery1.Eof do
Begin
with AdoQuery2 do
Begin
****
SQl.text:='Select * from table where column='''+AdoQuery1.fieldbyname('column').Asstring+'''';
End;
****在这里判断,是否查询到你要跟新的信息
在这里直接跟新‘update table *** set column='''+AdoQuery2.fieldbyname('colun').Asstring+'''+';'’//在这里添加特殊字符,以后如果需要某个text的内容,就可以使用pos,取到原来的text内容
AdoQuery1.next;
end;
写的有点乱,,,
可能是我表述有些问题, 我的问题是这样, 有两个AdoQuery, AdoQuery1和AdoQuery2,其中AdoQuery2 里有多个满足条件的 text 字段, 现在我需要把 所有满足条件的 AdoQuery2中的text 字段的内容, 都加到 AdoQuery1的一个text 字段内, 我说的显示设置,是AdoQuery2字段内的有些内容中包含了字体颜色和大写,这样在 richedit 中也能体现出来不是说要定位后自己作特殊显示, 我一开始用 stream , 但只能取一个, 后来使用 Cus.FieldByName( '建议 ').Value := Cus.FieldByName( '建议 ').Value +
cnKeyW.FieldByName( '内容 ').Value; 这种相加, 还是只有第一个, 如果用显示的 cnKeyW.FieldByName( '内容 ').asstring 那就只有字符穿了 谢谢
看来这个不是问题
2: 我说的显示设置,是AdoQuery2字段内的有些内容中包含了字体颜色和大写,这样在 richedit 中也能体现出来 不是说要定位后自己作特殊显示
:显示特殊条件text并在edit体现出来,那就使用颜色颜色把那些表示出来
如下
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
begin
str:='select ******** ';
AdoQuery1.Close ;
Adoquery1.SQL.Clear ;
AdoQuery1.SQL.Add(str) ;
Adoquery1.Open;
end;procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DbGrid1 do
begin
if adoquery1.FieldByName('code_').asstring = '' then
begin
Canvas.Brush.Color:=clWhite; //背景色
Canvas.Font.Color:= clRed; //字体色
end
Else if adoquery1.fieldbyname('code_').AsString <> '' then
begin
Canvas.Brush.Color:= ClWhite;
Canvas.font.color:= clGreen;
end;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
cnKeyW.FieldByName( '内容 ').Value; 这种相加, 还是只有第一个, 如果用显示的 cnKeyW.FieldByName( '内容 ').asstring 那就只有字符穿了
:显示cnKeyW.FieldByName( '内容 ').asstring :可以使用临时表Clientdatset了,那就不用使用字符串了
如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
DBGrid1.DataSource := DataSource1;
DataSource1.DataSet := ClientDataSet1;
with self.ClientDataSet1 do
begin
with FieldDefs.AddFieldDef do
begin
DataType:= ftString;
Name := 'col1';
Size := 100;
end;
CreateDataSet;
Append;
FieldByName( 'col1' ).AsString:='hello world';
Post;
end;
end;
------
adocommand1.CommandText:='exec sf_药品发出 ';//sf_药品发出这个为存储过程名称
adocommand1.Execute;//紧供参考,,,
1,假设是(1:1)关联关系,可以直接通过sql语句更新
update new_table set total_text = a.sub1_text + b.sub2_text
where id in(select id from from old1_table a, old2_table b where a.id=b.id and new_table.id = a.id)
2,
insert into new_table (total_text) values(select a.sub1_text, b.sub2_text from old1_table a, old2_table b where a.id=b.id)
恼了,如过你有时间把你的表的部分信息发CC一份给我(说详细一些,或者使用发表的信息放到EXCEL,说明那几个字段合并等要求),我一定帮你搞顶,[email protected]
我有两个表
表一:
id : integer;
month : double;
con : text;
表二:
id : integer;
con : text;
现在 我需要通过select con from 表一 where month = 2.1 // 满足条件即可, 这样得到的就有多条text 内容
然后我需要把刚才得到的 多条 表一的 text 内容 合并到 表二的 text 字段中,
我这段程序在 com+ 中实现 , 查询 表一的条件 来自客户端
多谢