當前位置:首頁 » 編程語言 » sql2005if

sql2005if

發布時間: 2023-03-05 19:00:04

Ⅰ 在sql2005資料庫執行存儲過程出現:關鍵字 'SET' 附近有語法錯誤。 怎麼處理呀代碼如下

換成

CREATE proc [dbo].[GetDataSet]
@TableList Varchar(1024)='*',--搜索表的欄位,比如:』id,datatime,job『,用逗號隔開
@TableName Varchar(100), --搜索的表名
@SelectWhere Varchar(1024)='',--搜索條件,這里不用寫where,比如:job=』teacher『and class='2'
@SelectOrderId Varchar(50),--表主鍵欄位名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多欄位排序但主鍵欄位必需在最前面.也可以不寫,比如:order by class asc
@intPageNo int=1, --頁號
@intPageSize int=10 ,--每頁顯示數
@RecordCount int OUTPUT --總記錄數(存儲過程輸出參數)
as
declare @TmpSelect NVarchar(4000)
declare @Tmp NVarchar(4000)
declare @pagecount int
set nocount on--關閉計數
set @RecordCount=0
set @TmpSelect = 'select @RecordCount=count(*) from '+@TableName+' where '+@SelectWhere
execute sp_executesql
@TmpSelect, --執行上面的sql語句
N'@RecordCount int OUTPUT' , --執行輸出數據的sql語句,output出總記錄數
@RecordCount OUTPUT
if (@RecordCount = 0) --如果沒有貼子,則返回零
return 0
set @pagecount = @RecordCount/@intPageSize
if(@RecordCount%@intPageSize>0)
set @pagecount=@pagecount+1
if(@pagecount<=0)
set @pagecount=1
if(@intPageNo>@pagecount)
set @intPageNo=@pagecount
/*判斷頁數是否正確*/
--if (@intPageNo - 1) * @intPageSize > @RecordCount --頁號大於總頁數,返回錯誤
--set @intPageNo=@pagecount
set nocount off--打開計數
if @SelectWhere != ''
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+''+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO

Ⅱ 用SQL 2005編程:求出1~999之間所有的同構數(一個數出現在其平方的右側)。

declare @n int,@m int;
declare @t table(同構數 int)
set @n=0;
while(@n<999)
begin
set @n=@n+1;
select @m= case when @n<10 then 10 when @n<100 then 100 else 1000 end;
if (@n*@n-@n)%@m=0
insert into @t values (@n)
end
select * from @t結果:
同構數
1
5
6
25
76
376
675

熱點內容
天天愛消除卡心腳本 發布:2024-05-20 13:01:00 瀏覽:124
python中str的意思 發布:2024-05-20 13:00:52 瀏覽:235
隨機訪問方式 發布:2024-05-20 12:42:52 瀏覽:258
php判斷登陸 發布:2024-05-20 12:14:24 瀏覽:629
腳本精靈並且 發布:2024-05-20 11:39:40 瀏覽:266
綠盟登陸器單機怎麼配置列表 發布:2024-05-20 11:34:34 瀏覽:971
Android省電軟體 發布:2024-05-20 11:25:00 瀏覽:341
android鍵盤隱藏 發布:2024-05-20 11:23:40 瀏覽:523
瘋狂點擊的點擊腳本 發布:2024-05-20 11:09:06 瀏覽:686
飯團文件夾 發布:2024-05-20 10:56:18 瀏覽:575