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
 General SQL Server Forums
 New to SQL Server Programming
 Error casting or converting varchar

Author  Topic 

mrtweaver
Yak Posting Veteran

67 Posts

Posted - 2009-04-08 : 08:46:22
Running SQL 2005, have a table which is used by an OEM program that I have copied over to a view, this way it does not affect the table or the OEM program. When I look at the data types in the view the one column is set at VARCHAR(8000). So in the view I thought I could just use the CAST or CONVERT to transform it over to a BIGINT. here is the code I tried:

SELECT CAST(JOBTASK AS BIGINT) as JOBTASK, OPCODE, KEYFIELD FROM ABC

When I got the error message I tried:

SELECT CONVERT(BIGINT,JOBTASK), OPCODE, KEYFIELD FROM ABC

No matter which way I have tried this I get the following error message: ERROR MESSAGE: CAN NOT CALL METHODS ON BIGINT.

What the heck does this mean? Why wont the CAST or CONVERT function properly?

Thanks and have a great day.

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-04-09 : 03:58:37
Where are you running this qeury?
Query designer?

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

mrtweaver
Yak Posting Veteran

67 Posts

Posted - 2009-04-09 : 07:50:52
Yes I am running it in the GUI query designer. Currently the only way I know of working with SQL is thru the Management Studio GUI. The funny thing is I can take any of the other component that make up the query and use CAST or CONVERT and they work just fine. But for some reason it will not work on this JobTask column and keep comming up with the error as posted. I have also tried to relay out the order in the select statement to see if placing the items in a different order would fix the problem but still it keeps comming up with the error. Maybe it has problems converting a VARCHAR to a BIGINT. I dont know. You look at the data in the OEM's table and the column is set as VARCHAR(8000), if I just select this column in my view it comes over as a varchar(8000), if I use cast or convert and set it as VARCHAR(20) the cast and convert function properly but when I try to change it to BIGINT or INT I get the error.


quote:
Originally posted by Mangal Pardeshi

Where are you running this qeury?
Query designer?

Mangal Pardeshi
http://mangalpardeshi.blogspot.com

Go to Top of Page

pmohans123
Starting Member

5 Posts

Posted - 2009-04-10 : 06:07:06
Hi,

If you are varchar(8000) column has any one character value(non numeric) in it then you can't convert. check that
Go to Top of Page
   

- Advertisement -