关于sql server存储过程
createprocedureproc(inpageNumint,inrowNumint)beginset@startRow=(pageNum-1)*rowNum;set...
create procedure proc(in pageNum int,in rowNum int)
begin
set @startRow=(pageNum-1)*rowNum;
set @rowNum=rowNum;
prepare stmt from 'select * from tbl_book limit ?,?';
execute stmt using @startRow,@rowNum;
end
这是在Mysql中的存储过程,求大神帮我改成SQL server的。。。 谢谢 展开
begin
set @startRow=(pageNum-1)*rowNum;
set @rowNum=rowNum;
prepare stmt from 'select * from tbl_book limit ?,?';
execute stmt using @startRow,@rowNum;
end
这是在Mysql中的存储过程,求大神帮我改成SQL server的。。。 谢谢 展开
2个回答
展开全部
1、
CREATE FUNCTION return_num
(@Class_Num varchar(20) )
RETURNS int
AS
BEGIN
RETURN ( select cout(*) from classmates where classnum=@Class_Num )
END
3、
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database 数据库名字' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database 数据库名字'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'备份数据库名字',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'每天上午数据库备份',
@category_name=N'Database 数据库名字',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'declare @strDate nvarchar(max);
set @strDate = N''D:\DataBaseAutoBackup\数据库名字_'' + Convert(nvarchar(8),getdate(),112) + N''.bak''
BACKUP DATABASE [数据库名字] TO DISK = @strDate WITH NOFORMAT, NOINIT, NAME = N''数据库橘差名字_Dev-完整 数据库 备份'', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO',
@database_name=N'master',
@flags=0
IF (@@ERROR <厅薯> 0 OR @ReturnCode <>圆伏皮 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Daily Backup',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120510,
@active_end_date=99991231,
@active_start_time=50000,
@active_end_time=235959,
@schedule_uid=N'f90cfdc3-cb5d-4e19-9e93-99b8921d36c0'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
是否可以解决您的问题?
CREATE FUNCTION return_num
(@Class_Num varchar(20) )
RETURNS int
AS
BEGIN
RETURN ( select cout(*) from classmates where classnum=@Class_Num )
END
3、
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database 数据库名字' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database 数据库名字'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'备份数据库名字',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'每天上午数据库备份',
@category_name=N'Database 数据库名字',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'declare @strDate nvarchar(max);
set @strDate = N''D:\DataBaseAutoBackup\数据库名字_'' + Convert(nvarchar(8),getdate(),112) + N''.bak''
BACKUP DATABASE [数据库名字] TO DISK = @strDate WITH NOFORMAT, NOINIT, NAME = N''数据库橘差名字_Dev-完整 数据库 备份'', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO',
@database_name=N'master',
@flags=0
IF (@@ERROR <厅薯> 0 OR @ReturnCode <>圆伏皮 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Daily Backup',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120510,
@active_end_date=99991231,
@active_start_time=50000,
@active_end_time=235959,
@schedule_uid=N'f90cfdc3-cb5d-4e19-9e93-99b8921d36c0'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
是否可以解决您的问题?
追问
能不能别粘? 好好看看?
展开全部
create procedure proc(@pageNum int,@rowNum int)
as
begin
declare @startRow int;set @startRow=(@pageNum-1)*@rowNum;
declare @endRow int;set @endRow=@pageNum*@rowNum;
execute sys.sp_executesql N'
select 郑拆哗御扒* from (
select *,row_number() over (order by (select 1)) as seq from tbl_book
) t where seq>@startRow and seq<=@endRow'
,N'@startRow int,@endRow int'
喊行 ,@startRow,@endRow;
end
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询