Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

mixing numeric and text data in a single column Expand / Collapse
Author
Message
Posted Wednesday, January 26, 2011 11:55 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:19 PM
Points: 656, Visits: 3,935
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
Post #1054121
Posted Wednesday, January 26, 2011 12:00 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
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
Post #1054125
Posted Wednesday, January 26, 2011 12:49 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 10:07 AM
Points: 14,034, Visits: 28,406
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
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1054162
Posted Wednesday, January 26, 2011 2:59 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:25 PM
Points: 7,868, Visits: 9,607
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
Post #1054259
Posted Wednesday, January 26, 2011 3:19 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:19 PM
Points: 656, Visits: 3,935
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.
Post #1054267
Posted Wednesday, January 26, 2011 3:26 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:19 PM
Points: 656, Visits: 3,935
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.
Post #1054271
Posted Thursday, January 27, 2011 6:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
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
Post #1054521
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse