I am not sure what I am doing wrong but I am getting the following error in a subquery
Select*
from
(select
CONVERT (BIGINT,AX$AC1) as [Account]
from
[x].[y]
where [AXOBJ] >399999 AND [AX$AC1] NOT like '%NON BENCHMARK%')a
where a.[Account]>=510980
It returns Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to bigint.
I ran following to capture the data type of this table
select * from INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='y'
| COLUMN_NAME | DATA_TYPE |
|-------------|-----------|
| AXOBJ | char |
| AX$AC1 | char |
The following code return 39 integer values
select
CONVERT (BIGINT,AX$AC1) as [Account]
from
[x].[y]
where [AXOBJ] >399999 AND [AX$AC1] NOT like '%NON BENCHMARK%' GROUP BY AX$AC1
I am not sure where it going wrong.
CONVERT (BIGINT,AX$AC1)withTRY_CONVERT(BIGINT,AX$AC1). I bet you get someNULLvalues. But why are you storing numerical data as avarcharanyway? A value like'1.0'cannot be converted to abigint. - LarnuTRY_CONVERT(BIGINT,AX$AC1)returns bunch of null values. I modified my query aswhere [AXOBJ] >399999 AND [AX$AC1] NOT like '%NON BENCHMARK% AND TRY_CONVERT(BIGINT, AX$AC1)>=510980. It is giving me what I need. But why are you storing numerical data as a varchar anyway? _ I am not the DBA. I am just accessing the view. Thanks a lot again. - smpa01