Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlserver×Ö·û´®²ð·Ö(split)·½·¨»ã×Ü

sqlserver×Ö·û´®²ð·Ö(split)·½·¨»ã×Ü
--·½·¨0£º¶¯Ì¬SQL·¨
declare @s varchar(100),@sql varchar(1000)
set @s='1,2,3,4,5,6,7,8,9,10'
set @sql='select col='''+ replace(@s,',',''' union all select ''')+''''
PRINT @sql
exec (@sql)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_splitSTR]')
and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_splitSTR]
GO
--·½·¨1£ºÑ­»·½ØÈ¡·¨
CREATE FUNCTION f_splitSTR(
@s   varchar(8000),   --´ý·Ö²ðµÄ×Ö·û´®
@split varchar(10)     --Êý¾Ý·Ö¸ô·û
)RETURNS @re TABLE(col varchar(100))
AS
BEGIN
 DECLARE @splitlen int
 SET @splitlen=LEN(@split+'a')-2
 WHILE CHARINDEX(@split,@s)>0
 BEGIN
  INSERT @re VALUES(LEFT(@s,CHARINDEX(@split,@s)-1))
  SET @s=STUFF(@s,1,CHARINDEX(@split,@s)+@splitlen,'')
 END
 INSERT @re VALUES(@s)
 RETURN
END
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_splitSTR]')
and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_splitSTR]
GO
--·½·¨2£ºÊ¹ÓÃÁÙʱÐÔ·Ö²ð¸¨Öú±í·¨
CREATE FUNCTION f_splitSTR(
@s   varchar(8000),  --´ý·Ö²ðµÄ×Ö·û´®
@split varchar(10)     --Êý¾Ý·Ö¸ô·û
)RETURNS @re TABLE(col varchar(100))
AS
BEGIN
 --´´½¨·Ö²ð´¦ÀíµÄ¸¨Öú±í(Óû§¶¨Ò庯ÊýÖÐÖ»ÄܲÙ×÷±í±äÁ¿)
 DECLARE @t TABLE(ID int IDENTITY,b bit)
 INSERT @t(b) SELECT TOP 8000 0 from syscolumns a,syscolumns b
 INSERT @re SELECT SUBSTRING(@s,ID,CHARINDEX(@split,@s+@split,ID)-ID)
 from @t
 WHERE ID<=LEN(@s+'a')
  AND CHARINDEX(@split,@split+@s,ID)=ID
 RETURN
END
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_splitSTR]')
and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_splitSTR]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tb_splitSTR]')
and objectproperty(id,N'IsUserTable')=1)
drop table [dbo].[tb_splitSTR]
GO
--·½·¨3£ºÊ¹Ó


Ïà¹ØÎĵµ£º

Ò»Ö»²éѯSQLServer 2005ËùÓÐÐÅÏ¢µÄÓï¾ä

select
    table_name=
    (
    case when t_c.column_id=1
        then t_o.name
        else ''
    end
    ),
    column_id=t_ ......

SQLServerµÄCONVERTº¯Êý½éÉÜ

±¾ÎÄÀ´×ÔCSDN²©¿Í£¬×ªÔØÇë±êÃ÷³ö´¦£ºhttp://blog.csdn.net/yf520gn/archive/2008/09/26/2982363.aspx
SELECT * from TB_MILES_CB_ORDER
WHERE convert(varchar(100),ORDER_DATE,102)= £¿
ORDER BY ORDER_NO
SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
SELECT CONVERT(varchar(100), GETDATE ......

sqlserver ÐÔÄÜÓÅ»¯£­£­Join˵Ã÷

ÓÉÓÚ¹¤×÷ÐèÇó£¬Òª¶Ô¸ºÔðµÄ²ú Æ·×öµãÐÔÄÜÓÅ»¯£¬ÔÚÍøÉÏÕÒµ½ÁËÏà¹ØµÄ¶«Î÷£¬Äà ³öÀ´Óë´ó¼Ò·ÖÏí£º
¿´µ½ºÜ¶àÅóÓѶÔÊý¾Ý¿âµÄÀí½â¡¢ÈÏʶ»¹ÊÇûÓÐÍ»ÆÆÒ»¸öÆ¿¾±£¬¶øÕâ¸öÆ¿¾±ÍùÍùÖ»ÊÇÒ»²ã´°Ö½£¬Ô½¹ýÁËÄ㽫¿´µ½Ò»¸öÐÂÊÀ½ç¡£
04¡¢05Äê×öÏîÄ¿µÄʱºò£¬ÓÃSQL Server 2000£¬ºËÐÄ±í£¨´ó²¿·ÖʹÓÃƵ·±µÄ¹Ø¼ü¹¦ÄÜÿ´Î¶¼ÒªÓõ½£©´ïµ½ÁË800ÍòÊý¾Ý ......

Sqlserver È¡ºº×ֵĵÚÒ»¸ö×Öĸ£¬·½±ãÄ£ºý²éѯ

 create function comm_getpy
(
    @str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
    set @word=left(@str,1)
    --Èç¹û·Çºº×Ö×Ö·û£¬·µ»ØÔ­×Ö·û
& ......

sqlserverÁ´½Ó·þÎñÆ÷ʹÓ÷½·¨

EXEC sp_addlinkedsrvlogin @rmtsrvname = 'serverontest', @useself = 'false', @locallogin = 'sa', @rmtuser = 'sa', @rmtpassword = 'passwordofsa'
Ìí¼ÓµÇ¼·½Ê½
ÒÔÉÏÁ½¸öÓï¾äÖУ¬@serverΪ·þÎñÆ÷µÄ±ðÃû£¬@datasrcΪҪÁ´½ÓµÄÄ¿±êÊý¾Ý¿âµÄÁ¬½Ó´®£¬@rmtsrvnameΪ±ðÃû,@localloginΪ±¾µØµÇ¼µÄÓû§Ãû£¬@rmtuserºÍ@rmtpa ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ