Casting integers....

Data Modeling

Casting integers....

OK.... i can't seem to get this to work... im doing an insert on a table and i want to move a VARCHAR into a INT. I'm trying to CAST it, but its not working... any ideas?

INSERT INTO tbl

(...

...)

SELECT 

CAST(NAME AS INT),

...

...

The receiving table is set up to receive as an int..

Any help is appreciated

Dan

4 REPLIES
N/A

Re: Casting integers....

Hi Dan,

my crystal ball is "not working", too.

What doesn't work, is there an error message?

Re: Casting integers....

Hi Dieter - 

I just cant figure out how to successfully cast a VARCHAR(5) into a INT field through a select. 

SELECT BlgProdInstID, AcctID, DataSrcTypeCd, 

CAST(BlgPrdSvcCd as int), 

BlgPrdPckgCd,

BlgPrdInstallCnt, SbscrSvcCntInd, RetailAmt, PrcBeforeDiscount,

PrcAfterDiscount, CustDiscountAmt, DiscountAmt, MultiCharge,

ItemType, MSOSvcCd, 

FROM Table

The error i get is that there is a bad character in the format or data....

N/A

Re: Casting integers....

but this means that at least one row contains a value which can't be converted into an integer.

Which version are you on?

Re: Casting integers....

Do you mean?
CAST(BlgPrdSvcCd as integer) and not as CAST(BlgPrdSvcCd as int)