Casting integers....

Data Modeling
Enthusiast

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
Junior Contributor

Re: Casting integers....

Hi Dan,

my crystal ball is "not working", too.

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

Enthusiast

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....

Supporter

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?

Enthusiast

Re: Casting integers....

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