报错:
在将 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
If you want to solve your question,you must put foword your question!
怎么置顶?
@星休: 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
@幻天芒: 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
@幻天芒: 帮看一下急
@星休: from之后不支持参数~
秀出你的代码, 这样的问题描述, 威武, 有希望了, 支持, 顶。