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

Sql Server2005¶Ôt sqlµÄÔöǿ֮Cross Apply

Cross Applyʹ±í¿ÉÒԺͱíÖµº¯Êý½á¹û½øÐÐjoin£¬ÔÚÏÂÃæµÄʾÀýÖн¨ÁËÁ½¸ö±íºÍÒ»¸ö±íÖµº¯Êý£¬T_bµÄÁÐa_idsÖÐ»á´æ·Åa±íµÄidÓÃ,·Ö¸îµÄ×Ö·û´®Á¬½Ó£»ÎÒÃÇͨ¹ýcross applyʹT_a£¬T_b±íͨ¹ýsplitIDs inner join Á¬½Ó¡£Ç뿴ʾÀý£ºGO
if object_id('T_a','U') is not null
drop table T_a
GO
CREATE TABLE T_a(    id int unique not null,
    name varchar(50),
)
GO
if object_id('T_b',N'U') is not null
drop table T_b
GO
create table T_b
(
    id int unique not null,
    name varchar(10),
    a_ids varchar(100) null --ÒªÔÚÕâÒ»ÁÐÖдæ·Åt_a±íµÄIDÐòÁÐ,ÕâÑù×öÁ¬µÚÒ»·¶Ê½¶¼Ã»ÓÐÂú×㣬µ«ÊÇÓÐʱºò¿¼ÂÇÐÔÄÜ»òÉè¼ÆÎÒÃÇ¿ÉÄÜ»áÏñÕâôÓÃ
)
GO
--³õʼ»¯Êý¾Ý
INSERT INTO T_a VALUES(1,'A-1')
INSERT INTO T_a VALUES(2,'A-2')
INSERT INTO T_a VALUES(3,'A-3')
INSERT INTO T_a VALUES(4,'A-4')
INSERT INTO T_a VALUES(5,'A-5')
INSERT INTO T_b VALUES(1,'B-1','1,2,4')
GO
--´´½¨Ò»¸ö±íÖµº¯Êý£¬ÓÃÀ´²ð·ÖÓöººÅ·Ö¸îµÄÊý×Ö´®£¬·µ»ØÖ»ÓÐÒ»ÁÐÊý×ֵıí
if object_id('splitIDs','TF') is not null
drop function splitIDs;
GO
create function splitIDs(
    @Ids nvarchar(1000)
)
returns @t_id TABLE (id bigint)
as
begin
    declare @i int,@j int,@l int,@v bigint;
    set @i = 0;
    set @j = 0;
    set @l = len(@Ids);
    while(@j < @l)
    begin
       set @j = charindex(',',@Ids,@i+1);
       if(@j = 0) set @j = @l+1;
       set @v = cast(SUBSTRING(@Ids,@i+1,@j-@i-1) as bigint);
       INSERT INTO @t_id VALUES(@v)
       set @i = @j;
    end
    return;
end
GO
--²âÊÔsplitIDsµÄÖ´ÐÐЧ¹û
select * from splitIDs('1,2,4,3')
select * from splitIDs('100')
select * from splitIDs(NULL)
GO
--ʹÓÃcross apply»ñµÃt_b±íÖÐÖ¸¶¨ÐжÔÓ¦µÄËùÓÐt_a±íÖеļǼ
select 


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......

[SQL 2000]·¢Éú´íÎó1069£ºÓÉÓڵǼʧ°Ü¶øÎÞ·¨Æô¶¯·þÎñ


´íÎó1069ÊÇÒ»¸öWindows NT/2000µÄϵͳ´íÎó¡£´íÎó1069±íÃ÷·þÎñ²»Äܱ»Æô¶¯£¨µ±Æô¶¯·þÎñʱ·µ»Ø“µÇ¼ʧ°Ü”´íÎ󣩡£ÀýÈ磬µ±Æô¶¯MSSQLServer·þÎñʱ£¬µÃµ½ÈçÏ´íÎóÌáʾ£º
·¢Éú´íÎó1069£ºÓÉÓڵǼʧ°Ü¶øÎÞ·¨Æô¶¯·þÎñ
´ËʱÕýÔÚMSSQLServer·þÎñÉÏÖ´Ðи÷þÎñ²Ù×÷
Èç¹û·þÎñ±»Ò»¸öûÓГµÇ¼·þÎñ”ȨÏÞµÄÕÊ» ......

ADOµÄSQLÓï¾äÖеġ°*¡±ºÍ¡°?¡±

ÓÉÓÚVBAÖдú±íµ¥¸öºÍ¶à¸ö×Ö·ûÊÇÓá°?¡±ºÍ¡°*¡±´ú±íµÄ£¬ËùÒÔÐí¶à¸ÕѧADOµÄÅóÓѾ­³£»áÎÊ£ºÎªÊ²Ã´ÔÚSQLÓï¾äÖÐÕâÁ½¸ö·ûºÅ²»ÄÜÓÃÄØ£¿Ó¦¸ÃÓÃʲô·ûºÅÀ´´ú±íÄØ£¿ ÕâÊÇÒòΪVBA+ADOËùÓõÄÇý¶¯µÄ¹ØÏµ£¬±¾È˶ÔÕâ¸öÒ²²»ÊÇÌ«¾«£¬¾ßÌå´ó¼Ò¿ÉÒÔȥ΢ÈíµÄÍøÕ¾ÉÏÕÒÕҴ𰸣¬ËùÒÔVBA+ADOµÄSQLÓï¾äÖеġ°*¡±ºÍ¡°?¡±ÕâÁ½¸ö·ûºÅÊÇÓá°%¡±ºÍ¡°_¡±£¬ ......

SQl server2000 ѧϰ×ܽá

ÉÏÖÜÒ»java µÄʧÀûÁË£¬ËäÈ»»¹Ã»Õýʽ¿ªÕâÃſΣ¬µ«ÎÒÒ²×ÔѧÁ˰ëÄ꣬Õâ´ÎµÄʧÀûÈÃÎÒÉî¿ÌÈÏʶÁË×Ô¼ºËù´æÔڵIJ»×㡣ΪÒÔºóѧϰÁôÏÂÁ˱¦¹óµÄ¾­Ñé¡£Ê컰˵£º¡°²»È뻢Ѩ£¬Ñɵû¢×Ó¡±¡£
ºóÌ죬ÎÒÒªÔÙÒ»´ÎÈ¥±±´ó¡£Õâ´Î¿¼SQL SERVER2000 £¬Í¬Ñù£¬ÕâÃÅ»¹Ã»Ñ§Í꣬Æäʵ£¬ÊǸտªÊ¼Ñ§¡£Ñ§µ½Á˵ÚÈýÕ¹ØÏµÄ£Ê½Éè¼ÆÔ­Àí £¬ ËäȻûÓбØÊ¤µÄÐÅÐÄ ......

sqlÄÚÖú¯Êý

Ò»°ãµØ£¬ÈÕÆÚ¸ñʽ˵Ã÷·ûÊDz»Ì«Ãô¸ÐµÄ¡£È»¶ø£¬µ±ÎªÁËÏÔʾ¶øËµÃ÷ÈÕÆÚ¸ñʽ¡¢¶ÔÓÚÎı¾Êý¾ÝÖеÄ˵Ã÷·ûµÈÇé¿öÏ£¬Ëü¾Í±äµÃ±È½ÏÎñʵ¡¢¾ßÌåÁË¡£ÒÔÔ·ݵÄÃû×ÖΪÀý£¬Í¨¹ýÏÂÃæÒýÓõĽá¹û½âÊÍһϸÃÇé¿öµÄЧ¹û£º
TO_CHAR(SYSDATE,’MONTH’)=NOVEMBER
TO_CHAR(SYSDATE,’Month’)=November
TO_CHAR(SYSDATE,&rsq ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ