Datatype Convert Char To Numeric

Dec 31, 2003

Hi,

I read the topic from JROdden and this case is similiar but...

I got several varchar fields with
values like
1.2
1.3
... these I can covert with
select CONVERT(dec(5,2), fieldname) as fieldname

In fact I also solved undefined- and NULL-values with.
CONVERT(decimal(12, 2), CASE WHEN GESCHKOSTMAX IS NULL OR
GESCHKOSTMAX < '0' THEN '0' ELSE GESCHKOSTMAX END) as GESCHKOSTMAX,

But now there are values like
1,4 and these ones neither CONVERT nor CAST will handle.

I tried the
SELECT DISTINCT KMPAUSCHALE
FROM extr_INTFIRMA
WHERE (isnumeric(KMPAUSCHALE) = 1)

and get
0,40
0.25
0.30 and so on...

The error is:
[Microsoft][ODBC SQL Driver][SQL Server]Error converting datatype varchar to decimal. (or float or numeric (whatever I tried))

I think the easiest way would be to insist on higher data quality but
I also would like to solve this interesting challenge.


Thanks for any hints

By the way, I followed rudys link to
http://rudy.ca/afdb.html
and now I know how I could protect myself !!!!

There must be a voice in my head saying:
Try the db-forum, try it and stay happy... ;-)

best regards and have fun with new year eve.

Michael

View 8 Replies


ADVERTISEMENT

Int Vs. Char For Datatype On Numeric Label?

Jul 12, 2007

I'm designing a database that will not be that large (I would be surprised if it ever surpassed 50,000 rows across all tables), but will be accessed quite often, so I am doing my best to optimize its structure, such as doing 3NF, selecting appropriate data types, etc.

I have a few columns that will contain numeric data (such as an invoice number (from an external source) or location ID). However, one of my classes in college was about database design, and we were taught that if you won't be doing mathmatic computation on a field (such as the invoice or location fields I mentioned earlier), then you should use a string literal type (char, varchar, etc.)

Unfortunatly, the professor did not explain much as to why this should be done. From the standpoint of semantic analysis, these types of fields are probably more labels than they are numbers. However, I don't find that very convincing (or even helpful).

In short, my question is that given a column holding numeric data that isn't worked on in a mathematical sense, is it really better to mark it as a string literal than a number? Any articles or studies I can read relating to this?

I would think that comparisons would be faster with int, as well as data storage (though, as mentioned, that's not as big of a concern). Sadly, Google doesn't have many helpful resources. (Lots of stuff on char vs varchar, though.)

View 12 Replies View Related

Convert Char Datatype To Datetime Datatype

Sep 17, 2003

Database is SQL Server 2000

I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.

What is the syntax to convert char(6) to datetime?

Thank you in advance.

View 1 Replies View Related

T-SQL (SS2K8) :: Convert Numeric Value To CHAR(7)

Sep 22, 2014

I have to store the result of a calculation in a column of type CHAR(7) (and am unable to change the column type).

The calculation can have results ranging in size from 0.1234567 to 99999999.

In the first case, I would need to store the value of 0.12345 in the column. In the later case, an error should be thrown.

So I need to store all of the significant digits from the left of the decimal (if there are < 7) and as many of the digits to the right as will fit into a CHAR(7), with the remaining precision being truncated.

View 6 Replies View Related

How To Convert From CHAR To Numeric In The Table

Sep 29, 2005

I have imported some data to sql2k from my old system. Somehow, it importedinvoice amount to char type.I just created another column called invamt2 type NUMERIC so I can copy orconvert content of invamt which is type CHAR. There are about 50,000records.How can I convert/cast from char type to numeric type ?Thanks

View 2 Replies View Related

Help Needed To Convert Char To Numeric

Feb 5, 2008



Hi ,

I am trying to convert a char field of lenght 5 into numeric (5,2) 999.99 format ,
i am getting an arithmentic overflow error.

The Character Data is 5 in length

It works fine if the Data is 00000
it fails if there is any number in the data

Like 10000
or 05000

How do i represent these into Numeric (5,2)

please let me know what taransformation to use and how.

Thanks,

View 2 Replies View Related

Convert T/F Char To Bit DataType

Jun 4, 2008

Hi all,
There are several columns called enabled with a char datatype in my database. One enabled column per table. These columns either have a value of T or F (true or false), depending on whether they're enabled or not. I want to change these columns to a bit datatype and insert the relevant value of true or false...
I guess the best way to do this is to add a new column to a table with a bit datatype, and based on the value in the current enabled column, insert TRUE or FALSE.
Anyone ideas on the best way to accomplish this?
Thanks.

View 4 Replies View Related

T-SQL (SS2K8) :: Varchar Datatype Field Will Ignore Leading Zeros When Compared With Numeric Datatype?

Jan 28, 2015

Need to know if the varchar datatype field will ingore leading zeros when compared with numeric datatype ?

create table #temp
(
code varchar(4) null,
id int not null
)
insert into #temp

[Code] .....

View 4 Replies View Related

Numeric Datatype To Ssis Variable Datatype Conversion Problem

Apr 24, 2008



Good afternoon,

I have an issue with an ssis variable datatype.

The scenario is as follows:

I have a stored procedure:


PROCEDURE [dbo].[sp_newTransaction]



@sourceSystem varchar(50),

@txOut NUMERIC(18,0) OUTPUT

AS

insert into scn_transaction (sourceSystemName) values(@sourceSystem);

SELECT @txOut = @@identity


Whose purpose is to perform an insert into a table and return me the identity value of the inserted record, which I'll then use throughout the rest of my package. The identity column in the inserted table is numeric(18,0).

I execute the stored proc with the following sql with an OLE DB connection manager:

exec sp_newTransaction ?, ?

The first parameter is a string variable from earlier in the package, and the second is the output parameter. I have the following parameter mappings to the execute sql task:

User:ystxId output numeric 1 -1
User:ourceSys input varchar 0 -1

The proc is correctly called, and the row insesrted, however I get a type conversion error when SSIS attempts to map the return parameter to my package variable... I've tried all sorts of combonations, and can't seem to get it to execute.

At one point I wasn't returning a numeric, but rather an int from the stored proc, and all was well until I went to use the variable in a derived column later in the package, and the type was converted quite incorrectly (a 1 was 77799789080 or some such), indicating a type conversion error likely related to the encoding of the number.

I'd like to keep the datatypes as numeric and make ssis use those - any pointers are greatly appreciated as to what type my package variable should be to allow proper assignment of a sql server numeric type to it.

Thanks much,

B

View 6 Replies View Related

Data Type Conversion - Numeric To Char

Jul 12, 2000

I would like to know how to translate a numeric value = 3 to a text or char value = 03.

Any input would be appreciated.

Thanks,


Joel

View 1 Replies View Related

Datatype Conversion (binary To Char)

Oct 25, 2000

here is my problem:
i have a variable @sid_x as binary(16) = 0x4CF254AB0BA5D411AA3E00508BC5C413
and i want to use it as argument in sp_addlogin statement.

select @sqlcmd = 'sp_addlogin "test", @sid = ' + @sid_t
/* this doesn't work, because @sid_t is binary... */

select @sqlcmd = 'sp_addlogin "test", @sid = ' + convert (char (20), @sid_x)
/* this doesn't work either, because it doesn't convert to binary text */

my question, is there any way i can get @sid_x in follow text format
0x4CF254AB0BA5D411AA3E00508BC5C413 ?

Thanks a lot!

View 1 Replies View Related

Changing Datatype From Char To Datetime

Jul 20, 2005

I am trying to run the following query:ALTER TABLE dnb_profileALTER COLUMN [family update date] datetimeand I keep getting the following error:Server: Msg 242, Level 16, State 3, Line 1The conversion of a char data type to a datetime data type resulted inan out-of-range datetime value.The statement has been terminated.Can anyone tell me how I can do this successfully??Thanks,Connie SawyerFoley & LardnerJoin Bytes!

View 2 Replies View Related

Character To Numeric Conversion Error- Select Statment On Char Column

Sep 18, 2007

Hi guys/ladies I'm still having some trouble formatting a select statement correctly.
I am using a sqldatasource control on an aspx page. It is connecting via odbc string to an Informix database.
Here is my select statement cut down to the most basic elements.
SELECT     commentFROM         informix.ipr_stucomWHERE     (comment > 70)
The column "comment" contains student grades ranging from 0-100 and the letters I, EE, P, F, etc. Therefore the column is of a char type. This is a problem because I cannot run the above statement without hitting an alpha record and getting the following error
"Character to numeric conversion error"
How can I write this statement where it will work in the datasource control and have it only look at numeric values and skip the alpha values?
I have tried case with cast and isnumeric... I don't think that I have the formating correct.
I have also used:
WHERE (NOT (comment = '  I' OR comment = ' EE' OR comment = ' NG' OR comment = ' WP' OR comment = ' WF' OR comment = '  P' OR comment = '  F'))
This works but is very clunky and could possibly break if other letters are input in the future. There has to be a better way.I am sorry for my ignorance and thanks again for your help.

View 2 Replies View Related

Store Phone Numbers/Zip Codes As Char(length) Or Numeric Datatypes?

Dec 18, 2003

I'm wondering which way is the best way to store your numeric values.
It probably doesnt matter, b/c you can always convert back and forth...but i'm just wondering what the best practice is i guess...


thx

View 1 Replies View Related

Raiserror For Datetime,numeric Datatype

Apr 9, 2007

Hi guys,
Can anybody tell how to raise an error for a datatype datatime and numeric.txs in advance

View 3 Replies View Related

What's Difference About Datatype Char,VarChar,NChar,NVarChar In Sql 2000 ?

Jan 9, 2006

Hi All:
         I am new to Sql 2000 database,Now  I'm planing to create a table in my databse,my table included below fields like this :
       PoNo(the length is 15 characters) ,Supplier Name(the length is 50 characters).etc
      but I don't how to select the datatype for them. should I  select  Char or VarChar ?
      which one is the best slection ?
  thans in advanced!
 
 
         
    

View 5 Replies View Related

SQL Server 2008 :: Get Time Difference Of Char Datatype Column Value

May 29, 2015

How can I get time difference of the following record :

STARTTIME ENDTIME
3:30 PM 4:30PM
7:30 PM 8:30PM

I have tried it by below query,

SELECT CONVERT(TIME,STARTTIME,108) - CONVERT(TIME,ENDTIME,108) FROM BATCH_MASTER

but it gives following error message

[color=red]Operand data type time is invalid for subtract operator.[/color]

View 6 Replies View Related

Determine Largest Numeric Datatype Scale Of A Column?

Oct 25, 2012

I would like to determine the largest numeric datatype scale of a column.

Decimal Largest Scale Solution found here.

Sample Data:

2222.0002430
2222.0000245
2222.0023455

View 1 Replies View Related

SSIS : Oracle As Datasource --&&> Issues With Numeric Datatype

Oct 17, 2007

Hello,

I have to develop a package to get some data from a 10g Oracle database and load it to a SQL Server 2005 database.

In my design I used Oracle Provider for OledDB as my source provider following Microsoft recommendations found here : http://msdn2.microsoft.com/en-us/library/bb332055.aspx

As I have to use a parametrized query against my Oracle database I create a variable with my query that I override at runtime with a script task to update the parameters values.

One of the return column is of numeric datatype.

To handle this known issue with Oracle sources I edited through the advanced editor my Oledb source component to manually correct the precision.

Everything works fine with one of my package.

So I repeat the whole process while designing an other one with the same purposes.

As for the previous one I first unit test every components and everything works. But when running the full package it raised an error code 0x80004005 Error while validating post executing phase of the component (sorry for the poor translation from french to english ...)

I open my dataflow where the component is and found no warnings or errors. I edited through the advanced editor my Oledb source component and found that there's an error on the precision scale of the numeric return column. The message warn me that the precision must be between 1 and 38.
I checked this column and in the "OLE DB Source output / External Columns" the precision is 0 though I previously manually corrected it.
I upadted again for a 18 precision as it is for this column in "OLE DB Source output / Output Columns".
But it never keeps my changes ......

I delete the component and recreate it to force the metadata to be updated but always the same thing, the precision scale for this column in the "OLE DB Source output / External Columns" never keeps my 18 value.

Does someone have any clues to help me ?

Thanks a lot.

Bertrand

View 4 Replies View Related

Convert Char(1) To Int

Feb 12, 2008

I'm looking through some data in a third party application, trying to figure something out for a report. There is a char(1) column holding control characters that apparently effects the status of certain records, and whether they should appear on the report. I want to look at the integer value of those characters rather than the character representation, but I can't get it to work. I keep getting "Error converting data type varchar to numeric." I'm trying to do something like this:
Code:

SELECT CONVERT(int, MyColumn) As IntValue FROM MyTable

I've tried every combination of cast and convert I can think of, as well as numeric data types other than int. There aren't that many distinct values, so I'm just going to do this manually, but I still want to know why it won't work, or what I'm doing wrong. Any thoughts?

View 2 Replies View Related

Convert Char(4) To Int

Jun 12, 2007

I have a Column called PostNr which is of type Char(4)
I want to be able to Convert it to int
How can I accomplish that in query analyser, I tried changing it in Ent Manager, it keeps timing out.
I data in Post is in this format, does not contain illegal character just number

View 5 Replies View Related

Convert Char To Decimal

Sep 29, 2007

 Hi all,I have a column LateHours (Varchar).  I want to put it in another table which has Latehours column in Decimal(4,2) Example   =  +04:33    Should be 4.33   (Only + values)                      Char   to               Decimal (4,2)   Please Help me,Thanks,Janaka 

View 3 Replies View Related

Please Help---Convert Varbinary To Char

May 31, 2002

I am trying to convert Varbinary to Char it keeps returning this ...


--------------------------------------------------
´å

(1 row(s) affected)


Here is the code that I am using....

declare @name varbinary(50)
set @name =0x12b4e5
SELECT Convert(char(50),@name)

Can someone please help! ~Dana

View 3 Replies View Related

Convert Char Into Datetime?

Mar 28, 2004

Hi,
I have DB2 date value 00000000. If I'm exporting to SQL server using openquery that is automaticaly converting to char of 8 and stored as the same value 00000000.
My question is how I can convert them as datetime value in SQL server 2000.?

View 1 Replies View Related

Convert Char To Datetime??

Jul 3, 2001

Have a requirement to:

Convert char(7) YYYY-MM variable (eg. '2001-07') to both:
datetime '2001-07-01 00:00:00.000' and
datetime '2001-07-01 23:59:59.997'

thx in advance!

View 2 Replies View Related

Convert Float To Char

May 23, 2008

hi, how can I convert a float to a char so I can do:

'£' + convert(char,amount) AS [money]

When I do the above the number is like 1.07848e+006
rather than 1078480


thans for any help.
jamie

View 20 Replies View Related

Can't Convert Data Into Char

May 26, 2008

if i use the query

SELECT iditem, CONVERT(char(20), dt, 105) FROM planeamento

it works just fine.. but in this case the dt (date) field is not recognised..

SELECT planeamento.iditem, idmodelo, item_planeamento.idproduto, item_planeamento.idpele, cor, ordemfabrico, qtd, CONVERT(char(20), dt, 105) FROM produto INNER JOIN item_planeamento ON produto.idproduto = item_planeamento.idproduto INNER JOIN planeamento ON item_planeamento.iditem = planeamento.iditem WHERE planeamento.idfabrica = 51 AND alterado = 'FALSE' AND estado = NULL GROUP BY planeamento.iditem, produto.idModelo, item_planeamento.idProduto, item_planeamento.idPele, item_planeamento.cor, item_planeamento.ordemFabrico, item_planeamento.qtd, planeamento.dt

before, id just had "id" where "CONVERT(char(20), dt, 105)" is, but the date was printed in a unwanted format..

can you help me?

thanks a lot!

View 5 Replies View Related

Convert Char To Date

Dec 26, 2014

declare @new table(
id int not null identity(1,1),
dat char(10))
insert into @new
select'111214'
union
select'121214'
select cast(dat as datetime)from @new
-----------------------

2011-12-14 00:00:00.000
2012-12-14 00:00:00.000

but me need results it
2014-12-11
2014-12-12

View 2 Replies View Related

Convert Float To Char

Aug 26, 2005

Select Cast('100.1234' as float)give me the result 100.1234Now when I convert it back to char I want exactly 100.1234Select Convert(char(100),Cast('100.1234' as float))Gives me 100.123 (Here I was expecting 100.1234)When I doSelect STR(Cast('100.1234' as float),25,4)I get back the result as 100.1234However here I am not sure how many digits do I have after the decimalpoint. If I put some value likeSelect STR(Cast('100.1234' as float),25,8)I get 0's appended to it, which is again not desired.Thanks in advance,Jai

View 4 Replies View Related

Cannot Convert A Char Value To Money.

Feb 22, 2008



We have the same database in three different environment. The statement below works just fine in two database environment, but I am getting the error in the third one. All the databases are Microsoft SQL Server 2005. I could not pine point the source of the issue. Please any input that you might be able to provide. Thanks



The issue in simplest from



DECLARE @UDF_Value nvarchar(255)

set @UDF_Value = 111



SELECT CONVERT(money, @UDF_Value)



Msg 235, Level 16, State 0, Line 1

Cannot convert a char value to money. The char value has incorrect syntax.









View 7 Replies View Related

Cannot Convert Char To Money

Sep 27, 2007

I've been trying to solve this problem or just find an alternative to do this. I have filled a temp table with certain values for all columns except those columns that rely on calculations that need certain cell values from other columns in the temp table. I have a while statement that runs through each cell for one calculation column and this is the code that updates the fields on the calc column:




Code Block
EXEC('UPDATE #tblTemp
SET #tblTemp.['+@CalcColumns+'] = (CAST(ISNULL((SELECT #tblTemp.['+@Column1+']
FROM #tblTemp
WHERE #tblTemp.PK = '''+@PubKey+'''), 0.00)as money) - CAST(ISNULL((SELECT #tblTemp.['+@Column2+']
FROM #tblTemp
WHERE #tblTemp.PK = '''+@PubKey+''') , 0.00)as money))
WHERE #tblTemp.PK = '''+@PubKey+'''')





The problem is that it will not let me convert the two values to money. The error is:


Msg 235, Level 16, State 0, Line 1

Cannot convert a char value to money. The char value has incorrect syntax.

This is necessary to calculate the difference between these two cells from the temp table. I would appreciate any help! Thanks!

View 6 Replies View Related

Convert Int Value To A Numeric.

Mar 12, 2008

Hi--

Got a column with int value and I need to sum the entire column by converting to a numeric.-- here what I have

select isnull(convert(varchar(15),sum(cast(columnName as numeric))),'0.00') from myTable-- But my outcome doesnt have decimal 0.00

any help?


Josephine

View 2 Replies View Related

Convert Char Into Integer For DB2 In DTS Package?

Mar 26, 2004

Hi,
I am extracting data from DB2 into SQL server using DTS. We have the data type char(5) in DB2 and int in SQL server.
I tried to give the
select integer(columname) as columname from tablename in data source.
I did parse the query it was Ok but If I tried to execute that giving the following error.
Can you give me your answere for this issue.


---------------------------
Package Error
---------------------------
Error Source : Microsoft OLE DB Provider for ODBC Drivers

Error Description : [StarQuest][StarSQL ODBC Driver][DB2]THE VALUE OF A CHARACTER STRING ARGUMENT WAS NOT ACCEPTABLE TO THE INTEGER FUNCTION

---------------------------
OK
---------------------------

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved