Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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"] ......

ibatisÖÐÖ±Ö´ÐÐsql£¬·µ»Ø´æ´¢MapµÄListÀàÐÍ

ibatis×÷Ϊһ¸öÇáÁ¿¼¶µÄorm¹¤¾ßÏÖÔڷdz£Á÷ÐУ¬ÎÒÔÚʹÓÃÖз¢ÏÖ£¬ÓÐʱ½ö½öÏ£Íû·µ»ØÒ»¸öÀàÐÍΪmapµÄlist¾Í¿ÉÒÔÁË£¬
±ÈÈç¼òµ¥µÄ²éѯͳ¼ÆÖ®ÀàµÄ£¬Ã»ÓбØÒª¶¨ÒåÌ«¶àµÄpojo£¬Òò´ËÏëÄܲ»ÄÜÔÚibatisÖÐÖ±½Ó´«ÈësqlÓï¾äÀ´Ö´ÐУ¬È»ºó·µ»ØmapÄØ£¿
´ÓÍøÉÏËÑÁËһϣ¬»¹ÕæÓУ¬ÊµÑé³É¹¦ºó×ܽáһϣ¬´ó¼Ò¹²Í¬½ø²½¡£ ÆäʵºÜ¼òµ¥£¬¾Í ......

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

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

ADO.NETÖеÄsqlÁ¬½Ó

using System.Data;            // Use ADO.NET namespace
using System.Data.SqlClient;  
 SqlConnection thisConnection = new SqlConnection(
      &nbs ......

SQL Server connection strings

SQL ODBC connection strings
Standard Security:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;"
Trusted connection:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=yes;" ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ