我正在创建一个智能列表,以便更好地查看报告。
我的问题是,当我在下面生成查询时,它会失败并出现此错误消息"转换varchar值时转换失败' Field2'到数据类型int。"
这是我的查询
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY [SECCODE]) AS RowNumber
FROM myDB.mySchema.myView
WHERE [Field1]<[Field2]) tempTable WHERE [tempTable].[RowNumber]>=1 AND [tempTable].[RowNumber]<=100
Field2来自文本框。我尝试输入确切的字段名称但我仍然得到错误。
请帮忙。提前谢谢。
答案 0 :(得分:0)
declare @v1 varchar(20);
select cast(@v1 as int)..
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY [SECCODE]) AS RowNumber
FROM myDB.mySchema.myView
WHERE [Field1]<cast([Field2] as int) tempTable WHERE [tempTable].[RowNumber]>=1 AND [tempTable].[RowNumber]<=100
答案 1 :(得分:0)
您是否尝试过使用cast
或convert
?
cast(varcharColumn as Int)
或CONVERT(INT, varcharColumn)