这是我的存储过程
[sp_Get_Data]
(
@IdParam INT,
@OrderBy varchar(50),
@Direc varchar(4),
)
AS
BEGIN
select
[LogID] //int
,[Address] //varchar
,[State] //varchar
,[City]
,[Zip]
FROM LogData
WHERE IdParam = LogID
order by
CASE @Direc
WHEN 'desc' THEN
CASE @OrderBy
WHEN 'LogID' THEN LogID
WHEN 'Address' THEN Address
END
END
DESC,
CASE @Direc
WHEN 'asc' THEN
CASE @OrderBy
WHEN 'LogID' THEN LogID
WHEN 'Address' THEN Address
END
END
EXEC [sp_Get_Data] @IdParam ='..' @OrderBy = 'LogID', @Direc = 'asc' // WORKS FINE
EXEC [sp_Get_Data] @IdParam ='..' @OrderBy = 'Address', @Direc = 'asc'
错误:
将 varchar 值“xyz”转换为数据类型 int 时转换失败。
如果我通过,而不是使用这个动态参数进行排序
ORDER BY Address ASC ....
这行得通。
我在这里缺少一些非常基本的东西吗?