I have a object with a data type of float, I need to change the data type to something that will allow a character to be added to the number but I don't want to use the wrong data type. The object is a simple number like 26273 and I would like to add a character like 26273B2. What data type would be wise to use that would not cause problems with the previous data all ready saved?
我有一个数据类型为float的对象,我需要将数据类型更改为允许将字符添加到数字但我不想使用错误的数据类型的内容。对象是一个简单的数字,如26273,我想添加一个像26273B2的字符。使用哪种数据类型不会导致以前的数据出现问题?
5 个解决方案
#1
You will want to use the Text type. That will allow numbers and characters.
您将需要使用文本类型。这将允许数字和字符。
#2
I guess that field isn't used to do calculations so TEXT would be good for you.
我想这个字段不用于计算,所以TEXT对你有好处。
Here is an useful table of MS Access field types.
这是一个有用的MS Access字段类型表。
#3
Possibly nvarchar if you wish to use a smaller field than text, and fix the length. varchar if you do not wish to use international character sets. nvarchar, I believe has more efficient indexing in most databases than text fields
如果你想使用比文本更小的字段,可能是nvarchar,并修复长度。 varchar如果您不想使用国际字符集。 nvarchar,我相信在大多数数据库中索引比文本字段更有效
#4
Use a NVARCHAR
column (a.k.a. Text) but if you only want to allow only digits and one or zero letters then you will need to add a CHECK
constraint or column-level Validation Rule. Let's assume you currently allow only positive integer values values between 1 and 9999999 (seven digits), you new table structure could look like this (Access database engine syntax in ANSI-92 Query Mode):
使用NVARCHAR列(a.k.a.Text)但如果您只想允许数字和一个或零个字母,则需要添加CHECK约束或列级验证规则。假设您当前只允许介于1和9999999之间的正整数值(七位数),您的新表结构可能如下所示(ANSI-92查询模式下的Access数据库引擎语法):
CREATE TABLE AccountNumbers (
account_nbr VARCHAR(8) NOT NULL UNIQUE,
CHECK (
RIGHT('0000000' & account_nbr, 8) LIKE '[A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][A-Z][0-9][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][A-Z][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][A-Z][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][A-Z][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][A-Z][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][A-Z][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
)
);
#5
You may want to add a separate field for the suffic and concatenate the two fields in various read only forms and reports.
您可能希望为suffic添加单独的字段,并在各种只读表单和报表中连接两个字段。
One reason is sequencing of data. When you put a number in a text field the following non intuitive sorting happens In your situation something like
一个原因是数据排序。当您在文本字段中放置一个数字时,会发生以下非直观排序:在您的情况下
26273B2
262893C4
26295A2
262966Q3
26297M3
26273B2 262893C4 26295A2 262966Q3 26297M3
will now happen. Whereas with the numeric field and a text field it will be
现在会发生。而数字字段和文本字段将是
26273 B2
26295 A2
26297 M3
262893 C4
262966 Q3
26273 B2 26295 A2 26297 M3 262893 C4 262966 Q3
Well, I tried to insert a space in front of the first three numbers in the above list but I have no idea how to force that with this HTML editor.
好吧,我试图在上面列表中的前三个数字前插入一个空格,但我不知道如何用这个HTML编辑器强制它。
#1
You will want to use the Text type. That will allow numbers and characters.
您将需要使用文本类型。这将允许数字和字符。
#2
I guess that field isn't used to do calculations so TEXT would be good for you.
我想这个字段不用于计算,所以TEXT对你有好处。
Here is an useful table of MS Access field types.
这是一个有用的MS Access字段类型表。
#3
Possibly nvarchar if you wish to use a smaller field than text, and fix the length. varchar if you do not wish to use international character sets. nvarchar, I believe has more efficient indexing in most databases than text fields
如果你想使用比文本更小的字段,可能是nvarchar,并修复长度。 varchar如果您不想使用国际字符集。 nvarchar,我相信在大多数数据库中索引比文本字段更有效
#4
Use a NVARCHAR
column (a.k.a. Text) but if you only want to allow only digits and one or zero letters then you will need to add a CHECK
constraint or column-level Validation Rule. Let's assume you currently allow only positive integer values values between 1 and 9999999 (seven digits), you new table structure could look like this (Access database engine syntax in ANSI-92 Query Mode):
使用NVARCHAR列(a.k.a.Text)但如果您只想允许数字和一个或零个字母,则需要添加CHECK约束或列级验证规则。假设您当前只允许介于1和9999999之间的正整数值(七位数),您的新表结构可能如下所示(ANSI-92查询模式下的Access数据库引擎语法):
CREATE TABLE AccountNumbers (
account_nbr VARCHAR(8) NOT NULL UNIQUE,
CHECK (
RIGHT('0000000' & account_nbr, 8) LIKE '[A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][A-Z][0-9][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][A-Z][0-9][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][A-Z][0-9][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][A-Z][0-9][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][A-Z][0-9][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][A-Z][0-9]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]'
OR RIGHT('0000000' & account_nbr, 8) LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
)
);
#5
You may want to add a separate field for the suffic and concatenate the two fields in various read only forms and reports.
您可能希望为suffic添加单独的字段,并在各种只读表单和报表中连接两个字段。
One reason is sequencing of data. When you put a number in a text field the following non intuitive sorting happens In your situation something like
一个原因是数据排序。当您在文本字段中放置一个数字时,会发生以下非直观排序:在您的情况下
26273B2
262893C4
26295A2
262966Q3
26297M3
26273B2 262893C4 26295A2 262966Q3 26297M3
will now happen. Whereas with the numeric field and a text field it will be
现在会发生。而数字字段和文本字段将是
26273 B2
26295 A2
26297 M3
262893 C4
262966 Q3
26273 B2 26295 A2 26297 M3 262893 C4 262966 Q3
Well, I tried to insert a space in front of the first three numbers in the above list but I have no idea how to force that with this HTML editor.
好吧,我试图在上面列表中的前三个数字前插入一个空格,但我不知道如何用这个HTML编辑器强制它。