0

My query is like this

    DataSet ds = SqlHelper.ExecuteDataset(GlobalSettings.DbDSN, CommandType.Text, 

 "SELECT TOP 1000 [ID],[Project]," +
         "[Owner], " +
         "[Consultant], " +
         "[Contractor], " +
         "[Value], " +
         "[Level1], " +
         "[Level2], " + 
         "[Status], " +
         "[Category], " +
         "[Country], " + 
         "[CreatedDate], " + 
         "[CreatedByID], " +
         "[CreatedByName] " +
   "FROM [Kontorting_Umbraco_DB].[dbo].[tbl_Projects] " +
  " where [Category] like '%' + @Category + '%' " + 
  "   and Country like'%'+ @country+'%' " + 
  "   and value like '%'+@Value+'%' " + 
  "        order by CreatedDate asc",

              new SqlParameter("@Category","water") ,
              new SqlParameter("@Country", "Bahrain"),
              new SqlParameter("@Value", 1000));

In this code "Value" field is float in the DB..And when I executes this I am getting an error

Conversion failed when converting the varchar value '%' to data type int.

can any one tell me how to use like query with float

4

1 回答 1

2

You are doing

value like '%'+@Value+'%'

, where value is int.

LIKE only works with expressions of character data type.

You could do

convert(nvarchar(100), value) like '%' + convert(nvarchar(100), @Value) + '%'

instead.

Note that you may have to adjust the length of the data (currently 100).

于 2013-07-20T13:38:55.933 回答