CREATE PROCEDURE GetProductByCategory
(
@categoryId int,
@pageSize int,
@pageIndex int
)
AS
DECLARE @sql nvarchar(4000)SET @sql = 'select top '+cast(@pagesize as varchar(20))+' * from ProductInfo
where CategoryId= '+cast(@categoryId as varchar(20))+'
and ProductInfo.ProductId not in (select top '+cast((@pageSize*@pageindex) as varchar(20))
+ ' ProductID from ProductInfo where CategoryId ='
+cast(@categoryId as varchar(20))+'order by productId) order by productId'
EXEC sp_ExecuteSql @sqlGO
EXEC sp_ExecuteSql @sql是什么用的?
(
@categoryId int,
@pageSize int,
@pageIndex int
)
AS
DECLARE @sql nvarchar(4000)SET @sql = 'select top '+cast(@pagesize as varchar(20))+' * from ProductInfo
where CategoryId= '+cast(@categoryId as varchar(20))+'
and ProductInfo.ProductId not in (select top '+cast((@pageSize*@pageindex) as varchar(20))
+ ' ProductID from ProductInfo where CategoryId ='
+cast(@categoryId as varchar(20))+'order by productId) order by productId'
EXEC sp_ExecuteSql @sqlGO
EXEC sp_ExecuteSql @sql是什么用的?
巅峰之道,高瞻才能远瞩;
实力之道,厚积而薄发;东莞打工者创业论坛:
http://211.148.133.100/work/
================================================================
不写?当然就不能运行了,。功能和exec(@sql)差不多,不过,EXEC sp_ExecuteSql可以带参数。
@admin varchar(50),
@adpwd varchar(50) OUTPUT
AS
select @adpwd=LogPwd from admin where LogId=@admin
GO
象这些都是没有的,都正常的,为什么上面的要EXEC sp_ExecuteSql ?
create table tb
(
id int,
content int
)insert into tb select 1,1--测试
declare @sql nvarchar(4000)
set @sql='select * from tb'
EXEC sp_ExecuteSql @sql--注意@sql这里代表的是一个合法的t-sql语句sp_Executesql执行的是这样的语句,而不是存储过程。
这句话等于execute(@sql)
Exec(@sql)代替就行了.
我知道,但为什么要写这东西呢?不写不是照样进行吗?
--没语言,我就不信上面的存储过程少了那句,你会得到一样的结果。