sql´æ´¢¹ý³Ì·ÖÒ³
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[pagination]
@tblName varchar(255), -- ±íÃû
@strGetFields varchar(1000), -- ÐèÒª·µ»ØµÄÁÐ
@fldName varchar(255), -- ÅÅÐòµÄ×Ö¶ÎÃû
@PageSize int, -- Ò³³ß´ç
@PageIndex int, -- Ò³Âë
@OrderType bit, -- ÉèÖÃÅÅÐòÀàÐÍ, ·Ç 0 ÖµÔò½µÐò
@strWhere varchar(1500), -- ²éѯÌõ¼þ (×¢Òâ: ²»Òª¼Ó where)
@rowCount int output, --²éѯµ½µÄ¼Ç¼Êý
@pagecount int output
AS
declare @strSQL varchar(5000) -- Ö÷Óï¾ä
declare @strTmp varchar(110) -- ÁÙʱ±äÁ¿
declare @strOrder varchar(400) -- ÅÅÐòÀàÐÍ
declare @strCountTmp nvarchar(100) --¼Ç¼Êý
begin
if @strWhere !=''
set @strCountTmp = 'select @rowCount = count(*) from [' + @tblName + '] where '+@strWhere
else
set @strCountTmp = 'select @rowCount = rowCount_tmp from tmp where (table_tmp = ''' + @tblName +''')'
exec sp_executesql @strCountTmp,N'@rowCount int out',@rowCount out --Êä³ö×ܼǼÊý
declare @totalpage int
set @pagecount=@rowCount/@PageSize
if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by ' + @fldName +' desc'
--Èç¹û@OrderType²»ÊÇ0£¬¾ÍÖ´ÐнµÐò£¬Õâ¾äºÜÖØÒª£¡
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by ' + @fldName +' asc'
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where ' + @strWhere + ' ' + @strOrder
else
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] '+ @strOrder
--Èç¹ûÊǵÚÒ»Ò³¾ÍÖ´ÐÐÒÔÉÏ´úÂ룬ÕâÑù»á¼Ó¿ìÖ´ÐÐËÙ¶È
end
else
begin
--ÒÔÏ´úÂ븳ÓèÁË@strSQLÒÔÕæÕýÖ´ÐеÄSQL´úÂë
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder
if @strWhere != ''
set @str
Ïà¹ØÎĵµ£º
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn= new SqlConnection("server=(local);database=colorring;uid=sa;pwd=;");
conn.Open();
string sqlstr = "exec master..xp_cmdshell 'bcp \"select top 100 * from master..aps\" queryout c:\\aa ......
1.ÈçºÎ½«Ò»¸öSQL Server±íµÄ½á¹¹¸´ÖƵ½ÁíÒ»¸öн¨µÄ±íÖÐ
select * into бí from ¾É±í where 0 = 1
2.ÐÞ¸Ä×Ö¶ÎĬÈÏÖµ
alter table ±íÃû add default ĬÈÏÖµ for ×Ö¶ÎÃû
3. È¡µÃÊý¾Ý¿â½á¹¹
SELECT name from sysdatabases
4.Ôö¼ÓÁÐ
......
Create PROCEDURE [dbo].[ChangeObjectOwner]
@OldOwner as NVARCHAR(128),
@NewOwner as NVARCHAR(128)
AS
DECLARE @Name as NVARCHAR(128)
DECLARE @Owner as NVARCHAR(128)
DECLARE @OwnerName as NVARCHAR(128)
DECLARE curObject CURSOR FOR
select 'Name' = name,
'Owner'&n ......
SQL Server 2005±¨ÁËÕâô¸ö´í£ºCannot resolve the collation conflict between "Chinese_PRC_CI_AS" and "Chinese_PRC_90_CI_AS" in the like operation.
ºó²éÖ¤£¬ÕâÊÇÓÉÓÚÁ½¸ö×ö±È½ÏµÄÁеÄÅÅÐò·½Ê½²»Í¬£¬ÖÐÎÄÓкܶàÖÖÅÅÐò·½Ê½£¬¶ÔÓ¦ÈçÏ£º
ÖÐÎÄ£¨Ïã¸ÛÌرðÐÐÕþÇø£©
Chinese_Hong_Kong_Stroke_90_CI_AS
ÖÐÎÄ£¨Ïã¸ÛÌرðÐ ......
1¡¢SessionÓÐʲôÖØ´óBUG£¬Î¢ÈíÌá³öÁËʲô·½·¨¼ÓÒÔ½â¾ö£¿
´ð£ºÊÇiisÖÐÓÉÓÚÓнø³Ì»ØÊÕ»úÖÆ£¬ÏµÍ³·±Ã¦µÄ»°Session»á¶ªÊ§£¬¿ÉÒÔÓÃSate server»òSQL ServerÊý¾Ý
¿âµÄ·½Ê½´æ´¢Session²»¹ýÕâÖÖ·½Ê½±È½ÏÂý£¬¶øÇÒÎÞ·¨²¶»ñSessionµÄENDʼþ¡£
2.²úÉúÒ»¸öintÊý×飬³¤¶ÈΪ100£¬²¢ÏòÆäÖÐËæ»ú²åÈë1-100£¬²¢ÇÒ²»ÄÜÖظ´¡£
C# ......