Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Conversion problem

Author  Topic 

a_r_satish
Yak Posting Veteran

84 Posts

Posted - 2006-03-04 : 03:40:29
Hi

In my database, i have two fields datatype and datasize.

It has to be inserted based on the condition given below. But i am getting the error that the data would be truncated.

Case when b.VarDtype = 'NUMBER' then b.varDLength else ''
end NumField,
Case when b.VarDtype <> 'NUMBER' then convert(int,b.varDlength) else '' end IntField,

where intfield is of type integer and numfield is of type varchar.

How to convert from varchar to int, without the data being getted truncated???

Thanks in advance.

Regards,
satish.r

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-04 : 03:46:53
Well, if the size of the varDlength field is greater then 4 bytes it will be truncted.. you can use bigint for that matter, since can store upto 8 bytes..

so your query will be somthing like this ..

Case when b.VarDtype <> 'NUMBER' then convert(bigint,b.varDlength) else '' end IntField

hope this works for you..


Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

a_r_satish
Yak Posting Veteran

84 Posts

Posted - 2006-03-04 : 04:16:01
Even bigint is not working. Again it says binary data would be truncated.

Any other alternative???



Regards,
satish.r
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-04 : 04:39:08
just check whether there is any character field in the column varDlength..then it wont be able to convert to int..

Can u post extact error what u r geting?

since max value that bigint can take is 9223372036854775807 ?? and i guess which is more then enough..???



Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

a_r_satish
Yak Posting Veteran

84 Posts

Posted - 2006-03-04 : 05:21:15
Ya got it, I used bigint only.
Problem solved.
Actually this time error was coz of some other field

Regards,
satish.r
Go to Top of Page
   

- Advertisement -