Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


mixing numeric and text data in a single column


mixing numeric and text data in a single column

Author
Message
Chrissy321
Chrissy321
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 4571
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
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14369 Visits: 9729
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
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17537 Visits: 32252
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 and SQL Server Execution Plans
Product Evangelist for Red Gate Software
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10688 Visits: 11991
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

Chrissy321
Chrissy321
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 4571
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.
Chrissy321
Chrissy321
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 4571
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.
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14369 Visits: 9729
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search