tags:

views:

134

answers:

5

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?

+2  A: 

You will want to use the Text type. That will allow numbers and characters.

Chalkey
And that should not affect any of the all ready saved data, ause I would hate to mess something up!
gary A.K.A. G4
You'll definitely want to make a backup before doing *anything*...but you should be safe.
Michael Haren
+2  A: 

I guess that field isn't used to do calculations so TEXT would be good for you.

Here is an useful table of MS Access field types.

victor hugo
And that should not affect any of the all ready saved data, cause I would hate to mess something up!
gary A.K.A. G4
No it won't. Anyway, as it is just an access database you might want to test in a copy first ;)
victor hugo
If by 'MS Access field types' you mean 'Access database engine data types' then your table is incomplete e.g. it is missing the Jet 4.0 BINARY data type and the ACE 2007 multi-value types.
onedaywhen
+1  A: 

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

Mark Schultheiss
For the Access database engine, TEXT is a synonym for NVARCHAR and VARCHAR is also a synonym for NVARCHAR. VARCHAR can notionally be achieved by using the WITH COMPRESSION qualifier in SQL DDL but I would still add a CHECK constraint e.g. CHECK(my_col NOT ALIKE '%[!0-9A-Z]%')
onedaywhen
A: 

You may want to add a separate field for the suffic and concatenate the two fields in various read only forms and reports.

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

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

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.

Tony Toews
You may find yourself constantly always concatenating values, a high price to pay for ease of sorting. Consider making the type CHAR(n) and mandate (via CHECK constraints or Validation Rules) leading zeros, which has the advantage of ensuring the arguably-duplicate values '055A' and '55A' cannot both occur. You could create a 'helper' PROCEDURES for INSERT and UPDATE to add leading zeros to values whose lengths are less than n.
onedaywhen
+1  A: 

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):

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]'
      )
);
onedaywhen
The original poster doesn't mention SQL Server anywhere. Does this work with a Access/Jet backend MDB/ACCDB?
Tony Toews
Sure does. I've edited it to make clear that it is Access database engine syntax in ANSI-92 Query Mode.
onedaywhen