SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Blank Space in an Integer Data Type Column View


Blank Space in an Integer Data Type Column View

Author
Message
AndrewSQLDBA
AndrewSQLDBA
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1780 Visits: 3427
Hello Everyone
Happy Friday

I am dealing with what I believe is Oracle that is the source of a SQL View.

I am seeing a data type of Integer in the View, but I am not able to see what makes up that View. When I query the View, I can see that an Integer data type column is storing a blank space. I use ISNUMERIC(ColumnName) = 0 and there are a lot of rows that show as a zero length blank space, or text, or something. I just know that it is not an Integer.

I have attempted to CAST and Convert this value, but it will not. I have changed the data type on the table that is being inserted in too, and it still fails with a Conversion error. I have tried REPLACE(), but still the same conversion error.

Do you happen to know of something else that I can try? This kind of thing working with Oracle or DB2 drive me crazy.

Thank you in advance for your comments, suggestions and time

Andrew SQLDBA
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15240 Visits: 18607
AndrewSQLDBA (4/4/2014)
Hello Everyone
Happy Friday

I am dealing with what I believe is Oracle that is the source of a SQL View.

I am seeing a data type of Integer in the View, but I am not able to see what makes up that View. When I query the View, I can see that an Integer data type column is storing a blank space. I use ISNUMERIC(ColumnName) = 0 and there are a lot of rows that show as a zero length blank space, or text, or something. I just know that it is not an Integer.

I have attempted to CAST and Convert this value, but it will not. I have changed the data type on the table that is being inserted in too, and it still fails with a Conversion error. I have tried REPLACE(), but still the same conversion error.

Do you happen to know of something else that I can try? This kind of thing working with Oracle or DB2 drive me crazy.

Thank you in advance for your comments, suggestions and time

Andrew SQLDBA


Test for the character code and if not within the digit (48-57) range, replace with 0
Cool

/* table variable for sample data */
DECLARE @NULLSTR TABLE
( NS_ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED NOT NULL
,STR_VAL VARCHAR(12) NULL
);
INSERT INTO @NULLSTR (STR_VAL)
/* Insert numbers, null and null replacement characters */
VALUES ('0'),('9'),(''),(NULL),(CHAR(32)),(CHAR(0)),('456');

SELECT
NS_ID AS NS_ID
,STR_VAL AS STR_VAL
,DATALENGTH(STR_VAL) AS DATALENGTH_STR_VAL
/* unicode function returns the character code of the first/only character */
,UNICODE(STR_VAL) AS UNICODE_STR_VAL
,ISNULL(UNICODE(STR_VAL),0) AS ISNULL_UNICODE_STR_VAL
,CASE /* if not in the number range 48-57 then return 0 else cast to int */
WHEN ISNULL(UNICODE(STR_VAL),0) BETWEEN 48 AND 57 THEN CAST(STR_VAL AS INT)
ELSE 0
END AS INT_STR_VAL
FROM @NULLSTR



Result set;
NS_ID       STR_VAL      DATALENGTH_STR_VAL UNICODE_STR_VAL ISNULL_UNICODE_STR_VAL INT_STR_VAL
----------- ------------ ------------------ --------------- ---------------------- -----------
1 0 1 48 48 0
2 9 1 57 57 9
3 0 NULL 0 0
4 NULL NULL NULL 0 0
5 1 32 32 0
6 1 0 0 0
7 456 3 52 52 456

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