table里为varchar型的某个字段,按一个按钮将其为数字与字符串分开,用Delphi该如何写?如table:ID Description
1 abc
2 123
4 xyz将Description字段中的abc和xyz放一起, 而123放另一个地方.
请大家给我一点思路.谢谢!
1 abc
2 123
4 xyz将Description字段中的abc和xyz放一起, 而123放另一个地方.
请大家给我一点思路.谢谢!
解决方案 »
- FastReport checkbox 用法
- 关于调用主程序与dll封装窗口的通讯问题????
- delphi的前景
- 关于dbgrid 的很菜的问题及IP地址获得的问题
- intraweb中iwdbgrid如何加入一个iwimage控件?
- 在调试《Delphi6开发人员指南》中16章中的环境菜单处理器时,出现一个错误提示:c:\winnt\explorer.exe找不到的错误
- GetModuleFileName的第一个参数如何获得?
- 我是一名程序员(zt),暴强
- 关于条码扫描仪的问题。100分。
- ADO连接DBF,为何出现这样的问题..........
- Borland Turbo Delphi 和 Delphi7 Delphi6这些有什么不同么?
- 请问有没有判断一个BMP图片中的某个点是否为白色的函数?必须自己写代码来比较该像素的RGB三个数组中的值吗?
给你个mysql的例子(其它数据库可作适当修改)
1.建表:
create table t3(id integer,Description varchar(10));
2.输入测试数据:
insert into t3 values(1,'abc');
insert into t3 values(2,'123');
insert into t3 values(3,'xyz');
3.用SQL得到结果:
select id,case cast(Description as UNSIGNED) when 0 then Description else '' end as c , case cast(Description as UNSIGNED) when 0 then 0 else Description end as n from t3;
结果:+------+------+------+
| id | c | n |
+------+------+------+
| 1 | abc | 0 |
| 2 | | 123 |
| 3 | xyz | 0 |
+------+------+------+
数字/字符分别在两个字段中.当然,你可单独取数字或字符
这样,在delphi中可直接得到要的结果了
如果,只单独取字符或数字,可用:
字符:
select id, Description from t3 where cast(Description as UNSIGNED)=0;
+------+-------------+
| id | Description |
+------+-------------+
| 1 | abc |
| 3 | xyz |
+------+-------------+
数字:
select id, Description from t3 where cast(Description as UNSIGNED)<>0;
+------+-------------+
| id | Description |
+------+-------------+
| 2 | 123 |
+------+-------------+
Create Table 表(IDDescription varchar(10))
--插入数据
insert into 表
select '1abc' union
select '2123' union
select '345' union
select '2134523' union
select '4512' union
select '12' union
select '34125' union
select '4xyz' union
select 'ddfgdf' union
select 'dfg' union
select 'sdfgdfdfg'
select * from 表
--测试语句
select * from 表 where ISNUMERIC(IDDescription)=0IDDescription
-------------
1abc
4xyz
ddfgdf
dfg
sdfgdfdfg(所影响的行数为 5 行)
select * from 表 where ISNUMERIC(IDDescription)=1IDDescription
-------------
12
2123
2134523
34125
345
4512(所影响的行数为 6 行)
--删除测试环境
Drop Table 表
select * from 表 where ISNUMERIC(IDDescription)=1
ADOQuery.SQL.Text := 'select * from 表';
ADOQuery.Open;var
I: Integer;with ADOQuery do
begin
while not Eof do
begin
if TryStrToInt(FieldByName('Description').Value, I) then//TryStrToInt64也可
begin
//这儿的Description是数字
end else
begin
//这儿的Description不是数字
end;
Next;
end;
end;