Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi all,

i have an simple sql query when i excute it is returning me an error:
Query:select canceltype,value from canceltype where companyid=1 and geolocationid= 1 and Canceltype=1

error:Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value 'Shortage of Vehicle' to data type int.

Table Structure:

SQL
CREATE TABLE [dbo].[CancelType](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [CancelType] [nvarchar](50) NULL,
    [Value] [int] NULL,
    [Companyid] [int] NULL,
    [Geolocationid] [int] NULL,
    [CType] [int] NULL
) ON [PRIMARY]


pls help me out
Posted
Comments
[no name] 1-Jun-13 12:22pm    
Ask yourself, if CancelType is a string "[CancelType] [nvarchar]", why are you trying to query it as if it were an integer, "Canceltype=1"?
ashok_89 1-Jun-13 12:40pm    
Thanks a lot,i have been spending 2 hours to figure it out, really the simple question worked a lot
ashok_89 1-Jun-13 12:41pm    
pls post this an solution so that i may rate it

1 solution

Try changing the column name "value" to TheValue. SQL may be interpreting this as a keyword. I could not find it in a list but you never know. You could also try enclosing the column names in []

select [canceltype],[value] from canceltype where companyid=1 and geolocationid= 1 and Canceltype=1
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900