All Forums Data Modeling
danimaltex 8 posts Joined 10/14
27 Oct 2014
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

Thanks, Dan
dnoeth 4628 posts Joined 11/04
27 Oct 2014

Hi Dan,
my crystal ball is "not working", too.
What doesn't work, is there an error message?

Dieter

danimaltex 8 posts Joined 10/14
27 Oct 2014

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

Thanks,
Dan

ulrich 816 posts Joined 09/09
27 Oct 2014

but this means that at least one row contains a value which can't be converted into an integer.
Which version are you on?

feel free to donate bitcoin:12kgAUHFUqvG2sQgaRBXFhCwyf9HXdkGud

Raja_KT 1246 posts Joined 07/09
27 Oct 2014

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

Raja K Thaw
My wiki: http://en.wikipedia.org/wiki/User:Kt_raj1
Street Children suffer not by their fault. We can help them if we want.

You must sign in to leave a comment.