January 26, 2011 at 11:55 am
Hello All,
My partner thinks its ok to send me a data file where they mix numeric and text data in a single column. When I protest they seem to think I am being a difficult.
Can anyone provide any links that detail the principle that I think they are violating?
Thanks
January 26, 2011 at 12:00 pm
The definition of relational databases and the normal forms for them is what I'd start with.
What kind of numeric and text data, and what difficulty does it create?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 26, 2011 at 12:49 pm
It kind of depends on what the data is. If it's an address, '1313 Mockingbird Lane,' I wouldn't sweat it (although, you can, I've seen systems that normalize street numbers). But if it's something like a an order system '32 Widgets' then yes, they should be seperating those out because the 32 is a different entity than the Widget and there's going to be reporting, etc., that needs to deal with that number as a number, and that string as a string.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 26, 2011 at 3:00 pm
Chrissy321 (1/26/2011)
Hello All,My partner thinks its ok to send me a data file where they mix numeric and text data in a single column. When I protest they seem to think I am being a difficult.
Can anyone provide any links that detail the principle that I think they are violating?
Thanks
Do you mean that this column can contain a mixture of text and numeric data in a single row, or that the column contain numeric data in some rows and text in others?
If the former, then provided the algebra defining the file format includes an atomic type which caters for such values, there's nothing wrong (but I don't recall ever seeing anyone produce such an algebra); if there is no such type in the algebra, then what's being violated is the principle of atomicity of attributes. However, I suspect you don't mean that (unless you mean that some of the text is characters like "123456789" in which case you should remember that that too is text, not numeric data, and Grant's post gives the standard example of those characters being part of the text not something not text but numeric).
If the latter, again it comes down to there being a suitably defined attribute type; this time what is needed is a type some of whose members are numeric things while some are text; if there isn't an appropriate attribute type defined for this column, then it is not possible to express the signature of the relation being represented, so fundametally it's violated the principle of being based on relational algebra.
But once again don't make the mistake of thinking that a string like "25 " is numeric, it isn't: it's text. Addresses are the classical example again, in a form somewhat different from that referred to by Grant. A house may have a name or a number or a number with an alphabetic qualifer, for example "25", "27A", "27B", "27C" and "Maddingey House" are five adjacent dwellings on the northern side of East Street. It's very common these days to split the house designator from the road name, city name, and county name; for example the information required by the UK post office and most UK financial institutions and mail order companies is the house designator and the Post Code (so house "College View" Post Code "XY12 4EQ" is all the address needed, and the house next door to that is house "78", Post Code "XY12 4EQ"). The house designator column sometimes contains text that looks like a number, and sometimes text that doesn't look like a number, but it's always text not numeric so far as the attribute type is concerned. This of course is a bit of a nightmare for sorting (you could invent a complicated datatype that contains hordes of geographic data in its definition and handles the sorting issues for you when you want to sort into postman's walk order, but mostly people just accept that the order implied by the behaviour of the attribute type is not the same as the order required by the application).
Tom
January 26, 2011 at 3:19 pm
GSquared (1/26/2011)
The definition of relational databases and the normal forms for them is what I'd start with.What kind of numeric and text data, and what difficulty does it create?
Hello,
You can see http://www.sqlservercentral.com/Forums/Topic1054055-338-1.aspx for the immediate problem I am facing.
The column can contain: 'T' or '49.10' both in a varchar column so I am having difficulty determining whether its numeric, if it is I need to perform a < or > evaluation.
January 26, 2011 at 3:26 pm
Thanks to all who replied. It is a situation where the data can be either a number I need to calculate with it or a textual code, not a combination or both. I should have been more specific.
I'm perfectly ok with storing a number in a text field if its not goingto be used in calculations, not the case here.
January 27, 2011 at 6:32 am
You can break up queries like that by doing the IsNumeric query to populate a temp table, then doing the rest of the action on the temp table, or by joining to the temp table.
-- This query separates the numbers from the text
select ID
into #T
from MyTable
where IsNumeric(MyColumn) = 1;
-- Do "math stuff" in this query
select *
from MyTable
where ID in (select ID from #T);
This avoids the "error converting" issues you're running into, and usually works well enough in terms of performance.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply