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

SQL ºÏ²¢ÐУ¬·µ»Ø´ø·Ö¸ô×Ö·ûµÄ×Ö·û´®

 
--ºÏ²¢ÐУ¬²¢·µ»ØºÏ²¢µÄÖµ
Create proc [dbo].[proUniteRow]
@tab varchar(30),           --±íÃû
@col varchar(30),           --ºÏ²¢µÄÁÐÃû
@where varchar(2000),      --ºÏ²¢µÄÌõ¼þ
@firstSplit varchar(100), --Á¬½Ó×Ö·ûǰ׺
@lastSplit varchar(100),  --Á¬½Ó×Ö·ûºó׺
@order varchar(100),       --ÅÅÐò
@val nvarchar(2000)='' output –·µ»ØÖµ
as
begin
 declare @sql nvarchar(2000)
 set @sql='
 declare @retStr varchar(2000)
 set @retStr=''''
 declare cur cursor
 read_only
 for select
 '+@col+' from '+@tab
 if len(@where)>0
 set @sql=@sql+' where '+@where
 
 if len(@order)>0
 set @sql=@sql+' order by '+@order
 
 set @sql=@sql+'
 declare @str varchar(2000)
 open cur
 fetch next from cur into @str
 while (@@fetch_status =0)
 begin
 set @retStr=@retStr+'''+@firstSplit+'''+@str+'''+@lastSplit+'''
 fetch next from cur into @str
 end
 close cur
 deallocate cur
 if len(@retStr)>0
 set @strEnd=substring(@retStr,1,len(@retStr)-1)
  '
 exec sp_executesql @sql,N'@strEnd nvarchar(2000) output',@val output
end
 
Ö´ÐУº
±ípro_lbsxb:
ID  lbsx_value  lbsx_isList  lbsx_order
1   A           1            1
2   B           1            2
3   C           1            3
4   D        &


Ïà¹ØÎĵµ£º

sqlÖÐand¼°or µÄÖ´ÐÐЧÂÊ

Ó¦ÓÃÖз¢ÏÖsqlÖеÄand¼°orµÄÖ´ÐÐЧÂÊÎÊÌâ
£ó£ñ£ìÓï¾ä£¬ÎªÊ²Ã´°Ñ×îºóµÄ£ï£ò»»³É£á£î£ä£¬²éѯµÄ¾ÍºÜ¿ì£¬Ê¹ÓõÄÊÇmssql·¶ÀýÖÐnorthwindÊý¾Ý¿âΪÀý£¬
select * from Orders a left join [Order Details] b on a.orderid = b.orderid
where a.customerid like '%ics%' or b.productid in (42,72)
×·×ÙÁËÓï¾äµÄÖ´Ðз½°¸,·¢ÏÖ ......

sql server³öÏÖÑ¡¶¨µÄÓû§ÓµÓжÔÏó¶øÎÞ·¨É¾³ýµÄ´¦Àí


sql server³öÏÖÑ¡¶¨µÄÓû§ÓµÓжÔÏó¶øÎÞ·¨É¾³ýµÄ´¦Àí
2006-4-5 19:50:00
·½·¨Ò»
Ê×ÏÈÄãÐèÒª×öµÄµÚÒ»¼þÊÂ
ÆóÒµ¹ÜÀíÆ÷-¡µÑ¡Ôñ·þÎñÆ÷-¡µÊô***-¡µ·þÎñÆ÷ÉèÖÃ-¡µÌôÉÏÔÊÐí¶ÔϵͳĿ¼¡£¡£¡£-¡µÈ·¶¨
µÚ¶þ²½
ÕÒµ½ÄãµÄÊý¾Ý¿âÕÒµ½sysusers±íÄÇÄãÒÔǰµÄÓû§É¾³ý
µÚÈý²½»ØÈ¥°ÉÊô***Öµ¸Ä»ØÀ´
µÚËIJ¿Öؽ¨Óû§¼´¿É
·½·¨¶þ
¶ ......

¡¾×ª¡¿¹ØÓÚ"µÝ¹éÊ÷ÐβéѯSQL"µÄºÃÌû

-----------------------------------------------------------------------------------------------------------------------
create table tb(id varchar(3) , pid varchar(3) , name varchar(10))
insert into tb values('001' , null  , '¹ã¶«Ê¡')
insert into tb values('002' , '001' , '¹ãÖÝÊÐ')
insert i ......

SQL Server 2005ÎÞ·¨Æô¶¯~£¡£¡£¡£¡

2010-05-05 13:35:52.06 Server Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
2010-05-05 13:35:52.06 Server (c) 2005 Microsoft Corporation.
201 ......

sqlÓïÑÔ£ºÈçºÎÅжÏ×Ö¶ÎÊÇ·ñ´æÔÚ£¬ÈçºÎɾ³ý¼°´´½¨×Ö¶Î

ÈçºÎÅжÏ×Ö¶ÎÊÇ·ñ´æÔÚ
 if col_length('±íÃû','×Ö¶Î1') is null  ALTER TABLE ±íÃû ADD ×Ö¶Î1 Nvarchar(50)  if col_length('±íÃû','×Ö¶Î2') is null  ALTER TABLE ±íÃû ADD ×Ö¶Î2 Nvarchar(50) ");
ɾ³ý×Ö¶Î
if col_length('±íÃû','×Ö¶Î1,') is not null  ALTER TABLE ±íÃû drop  c ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ