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

sql ²éѯÏȽøÏȳö

declare @tb3 table (ÉÌÆ·±àºÅ nvarchar(10),Åú´ÎºÅ nvarchar(10),¿â´æÊýÁ¿ int,³ö¿âÊýÁ¿ int)
declare @tb1 table (ÉÌÆ·±àºÅ nvarchar(10),Åú´ÎºÅ nvarchar(10),¿â´æÊýÁ¿ int)
insert into @tb1 select '0001','090801',200
      union all  select '0001','090501',50
      union all  select '0002','090101',30
      union all  select '0002','090701',200
declare @tb2 table (ÉÌÆ·±àºÅ nvarchar(10),¶©»õÊýÁ¿ int)
insert into @tb2 select '0001',60
      union all  select '0002',20
--declare @var int
declare c_sor cursor
for
select ÉÌÆ·±àºÅ,sum(¶©»õÊýÁ¿)¶©»õÊýÁ¿ from @tb2 group by ÉÌÆ·±àºÅ
declare @bh nvarchar(10), @dh int,@bh1 nvarchar(10),@pc nvarchar(10), @kc int
open  c_sor
fetch next from c_sor into @bh,@dh
while @@fetch_status=0
begin
declare sor cursor for select * from @tb1 where ÉÌÆ·±àºÅ=@bh order by Åú´ÎºÅ
open sor
fetch next from sor into @bh1,@pc,@kc
insert into @tb3 select @bh, @pc,@kc,case when @kc>@dh then @dh else @kc end
set @dh=@dh-@kc
while @dh>0
 begin
 fetch next from sor into @bh1,@pc,@kc
 insert into @tb3 select @bh, @pc,@kc,case when @kc>=@dh then @dh else @kc end
 set @dh=@dh-@kc
 end
close sor
deallocate sor
fetch next from c_sor into @bh,@dh
end
close c_sor
deallocate c_sor
select * from @tb3  order by ÉÌÆ·±àºÅ,Åú´ÎºÅ desc


Ïà¹ØÎĵµ£º

ASP.NET·ÀSQL×¢Èë½Å±¾³ÌÐò v2.0

public class SqlCheck
{
public SqlCheck()
{
//
// TODO: ÔÚ´Ë´¦Ìí¼Ó¹¹Ô캯ÊýÂß¼­
//
}

public SqlConnection oconn()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["StudyConnectionString"] ......

U9 SQLÓû§×Ô¶¨Ò庯Êý

ÔÚ×ö±¨±íʱoqlÓï¾äÖÐÓÐʱÐèÒªÓõ½Óû§×Ô¶¨Ò庯Êý£¬µ÷ÓÃÖ®ºó±¨±í±¨´í£º¡° ¶ÔÊý¾Ý¼¯¡°DataQuery¡±Ö´Ðвéѯʧ°Ü¡£ 'fn_GetLevelItemCatName' ²»ÊÇ¿ÉÒÔʶ±ðµÄ º¯ÊýÃû³Æ¡£ ')' ¸½½üÓÐÓï·¨´íÎó¡£ ¡° £¬ÓÚÊÇÎÒ½«oqlÓï¾ä½âÎöºóÄÃsqlÓï¾äµ½sql server 2008ÖÐÈ¥Ö´Ðб¨´í£º 'fn_GetLevelItemCatName' ²»ÊÇ¿ÉÒÔʶ±ðµÄº¯ÊýÃû³Æ¡£ ÕâÖÖÎÊÌ ......

ÈçºÎÇå³ýSQL serverÈÕÖ¾

  Ç°¼¸Ìì×öÒ»¸ö¹ØÓÚÊý¾Ý±íÓÅ»¯µÄ³ÌÐò£¬ÓÉÓÚÊý¾Ý¿âÀïÃæµÄ×ֶεĹØϵ·Ç³£¸´ÔÓ£¬²Ù×÷ÆðÀ´±È½ÏÂé·³£¬¸ÕÓõÄʱºò»¹ºÃ£¬ÔËÐÐʱ¼äÒ»³¤£¬Éú³ÉµÄÊÂÎñÈÕÖ¾ºÜ´ó£¬Õ¼ÓÃÁË10¼¸G£¬´ÅÅ̶¼¿ìÓÃÍêÁË¡£
    µ½ÍøÉÏËÑÁËһϣ¬·½·¨ÏÂÃæÁ½ÖÖ£º
    1.·ÖÀëÊý¾Ý¿â£¬Ö±½Óɾ³ýÊÂÎñÈÕÖ¾Îļþ£¬ÔÙ¸½¼ÓÊý¾Ý¿â£¬ÏµÍ³ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ