存储过程的一些小技巧
2007-09-29 21:57
204 查看
有时可能要在存储过程中根据输入的参数,构造SQL,并执行产生结果,可能还会碰到返回参数的问题,下面的一个存储过程中就用临时表来得到记录数,并赋值给返回参数
create proc [Test_CreatSQL_EXEC]
(
@FieldName varchar(50),
@StartTime DateTime,
@EndTime datetime,
@PageSize int,
@RecordCount int output
)
as
declare @SQL varchar(1000)
create table #tb
(
rows int
)
set @sql = 'insert into #tb select count(*) from Products where DateCreated between '''+ convert(varchar(20),@StartTime) + ''' and '''+convert(varchar(20),@endTime)+''''
exec (@sql)
select @RecordCount=rows from #tb
print @sql
drop table #tb
exec ('select top '+ @PageSize + ' * from Products where DateCreated between '''+ @startTime + ''' and '''+ @endtime +'''')
create proc [Test_CreatSQL_EXEC]
(
@FieldName varchar(50),
@StartTime DateTime,
@EndTime datetime,
@PageSize int,
@RecordCount int output
)
as
declare @SQL varchar(1000)
create table #tb
(
rows int
)
set @sql = 'insert into #tb select count(*) from Products where DateCreated between '''+ convert(varchar(20),@StartTime) + ''' and '''+convert(varchar(20),@endTime)+''''
exec (@sql)
select @RecordCount=rows from #tb
print @sql
drop table #tb
exec ('select top '+ @PageSize + ' * from Products where DateCreated between '''+ @startTime + ''' and '''+ @endtime +'''')
相关文章推荐
- 数据库是否使用外键,及视图,索引,存储过程的一些说明(zz)
- Ubuntu Linux使用过程中的一些小技巧
- 艾伟也谈项目管理,项目过程中所遇到的各种问题记录——有关MSChart的一些小技巧
- iOS开发过程中一些数据的存储归档
- SQL Server里一些未公开的扩展存储过程
- 关于存储过程的ADO调用的一些心得(输出参数,返回值)
- 关于存储过程的ADO调用的一些心得(输出参数,返回值)
- 关于MS2K一些存储过程的总结
- Yii2使用过程中一些小技巧的总结
- SQL Server创建链接服务器的一些存储过程和例子
- mysql 存储过程的一些问题
- ACM做题过程中的一些小技巧
- ACM做题过程中的一些小技巧
- Ubuntu17.04安装各种软件过程中出现的问题和一些小技巧
- 存储过程小技巧(2)----从动态查询SQL中返回值给变量
- 数据库是否使用外键,及视图,索引,存储过程的一些说明(zz)
- 程序书写过程中的一些小技巧
- ORACLE 有关存储过程的一些基础知识
- POI导入EXCLE过程中的处理日期类型单元格的一些小技巧
- SQL Server里一些未公开的扩展存储过程