首页 新闻 会员 周边

将 varchar 值@Condition 转换成数据类型 int 时失败。

0
悬赏园豆:30 [已解决问题] 解决于 2014-12-18 17:22

报错:

在将 varchar 值 'select ProductID from dbo.Product where PdTypeID in (select PdTypeID from dbo.ProductType where PdTypeParentID in (select PdTypeID from dbo.ProductType where PdTypeParentID=1))' 转换成数据类型 int 时失败。

visual代码:   string storeName = "pd_SearchHotTypeProduct";
           SqlParameter[] paramters = { new SqlParameter("@Condition",SqlDbType.VarChar,200) };
           paramters[0].Value = condtion;
           DataSet ds = DbHelperSQL.RunProcedureDs(storeName, paramters);
           return ds;

sql 存储过程:create procedure pd_SearchHotTypeProduct
(
@Condition varchar(250)--类型条件--
)
as
create table #ProductSell(ProductID int,totalSum int)--产品销售表--
insert into #ProductSell select ProductID,sum([Sum]) as totalSum from dbo.OrderList where ProductID in (@Condition) group by ProductID order by totalSum  desc
select top 15 ProductID,Name from dbo.Product where ProductID in
(select ProductID from #ProductSell )
drop table #ProductSell
go

星休的主页 星休 | 初学一级 | 园豆:4
提问于:2014-12-16 17:47
< >
分享
最佳答案
0

If you want to solve your question,you must put foword your question!

收获园豆:30
幻天芒 | 高人七级 |园豆:37175 | 2014-12-17 10:19

怎么置顶?

星休 | 园豆:4 (初学一级) | 2014-12-18 12:06

@星休: insert into #ProductSell select ProductID,sum([Sum]) as totalSum from dbo.OrderList where ProductID in (@Condition) group by ProductID order by totalSum  desc  这种代码是走不通的。不能直接在in里面跟动态sql。一般做法是你顶一个临时表,然后利用exec将@Condition的查询结果写入到临时表中,然后在in里面用,select * from #TempTable

幻天芒 | 园豆:37175 (高人七级) | 2014-12-18 13:24

@幻天芒: create procedure pd_SearchHotTypeProduct
(
@Condition varchar(250)--类型条件--
)
as
create table #ProductSell(ProductID int,totalSum int)--产品销售表--
create table #ConditionTable(ProductID int)
insert into #ConditionTable select ProductID from  (@Condition) as condition  --消息 102,级别 15,状态 1,过程 pd_SearchHotTypeProduct,第 8 行
')' 附近有语法错误。--
insert into #ProductSell select ProductID,sum([Sum]) as totalSum from dbo.OrderList where ProductID in (select ProductID from #ConditionTable) group by ProductID order by totalSum  desc
select top 15 ProductID,Name from dbo.Product where ProductID in
(select ProductID from #ProductSell )
drop table #ProductSell
go

星休 | 园豆:4 (初学一级) | 2014-12-18 17:33

@幻天芒: 帮看一下急

星休 | 园豆:4 (初学一级) | 2014-12-21 18:14

@星休: from之后不支持参数~

幻天芒 | 园豆:37175 (高人七级) | 2014-12-21 18:15
其他回答(1)
0

秀出你的代码, 这样的问题描述, 威武, 有希望了, 支持, 顶。 

问天何必 | 园豆:3311 (老鸟四级) | 2014-12-16 20:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册