ÇóÒ»¶Îsql²éѯ´úÂë - .NET¼¼Êõ / C#
ÎÒÏÖÔÚµÄÇé¿öÊÇÕâÑù£º
ÓÐÒ»¸öÊý¾Ý¿â½Ðsyslogd£¬
¿âÀïÃæÓкܶà±í£¬Ãû×ÖÖîÈ磺log_http_20100513,log_http_20100514,log_http_20100515,log_http_20100516,log_http_20100517........
ÏÖÔÚÖ»ÄÜÒ»ÌìÒ»Ìì°´ÌìËÑË÷¡£
ÎÒÏÖÔÚµÄÐèÇóÊÇ£ºÎҵIJéѯ½çÃæÓÐÁ½¸öʱ¼ä¿Ø¼þ£¬Ñ¡Ôñ¿ªÊ¼Ê±¼äºÍ½áÊøʱ¼äºó¿ÉÒÔ´ÓÕâÁ½¸öʱ¼ä¶ÎÄڵıíÀïÃæ°ÑËùÐèÒªµÄÊý¾ÝÈ«²¿¼ìË÷³öÀ´
ÓÐÅóÓѸøµÄ´úÂ룬ÔÚ²éѯ·ÖÎöÆ÷ÀïÃæÖ´ÐÐûÓÐÎÊÌ⣬ºÜºÃÓ㬵«ÊÇÎÒÏÖÔÚµÄÐèÇóÊÇÔÚc#Èí¼þ½çÃæµã»÷²éѯ°´Å¥Ö´ÐÐÕâ¸ösql²éѯ²Ù×÷£¬×Ô¼º²»»áÈÚ»á¹áͨ£¬Çë¸ßÊִͽ̡£
SQL code:
declare @d1 datetime,@d2 datetime
set @d1='2010-05-01'
set @d2='2010-05-03'
declare @tbname sysname
declare @sql varchar(8000)
while datediff(d,@d1,@d2)>=0
begin
begin
set @tbname='log_http_'+convert(varchar(8),@d1,112)
if object_id(@tbname) is not null
set @sql=isnull(@sql+' union all ','')+'select * from log_http_'+convert(varchar(8),@d1,112)
end
set @d1=@d1+1
end
print @sql
--select * from log_http_20100501 union all select * from log_http_20100502 union all select * from log_http_20100503
exec(@sql)
ÎÒµÄÏÖÔڵIJéѯ´úÂëÈçÏÂ
C# code:
private void buttonQuery_Click(object sender, EventArgs e)
{
string dbtablename = "log_" + comboBoxTableName.Text + "_
Ïà¹ØÎÊ´ð£º
×Ö¶Î1,×Ö¶Î2.....×Ö¶ÎN,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
ÏëÒªµÄ½á¹ûÊÇ:
1,Na ......
ÐèÇóÈçÏ£º
ѧԺ academy£¨aid,aname£©
°à¼¶ class£¨cid,cname,aid£©
ѧÉú stu(sid,sname,aid,cid)
סËÞÇø region(rid,rname)
ËÞÉáÂ¥ build(bid,rid,bnote) bnoteÊÇ¡®ÄС¯/¡®Å®¡¯
ËÞÉá dorm(did,rid,bid£¬bedn ......
ͨ¹ýNAME×Ö¶ÎÌõ¼þ²éѯһ¸öÊý¾Ý±í£¬¼ÙÉèÎÒÓÐ100¸öÐÕÃû£¬ÓÐÒÔÏÂÁ½¸ö·½·¨£¬
·½·¨1£º
°Ñ100¸öName ×é³ÉÒ»¸öSQLÓï¾ä£¬±ÈÈç Select * from tmp_table where Name='ÕÅÈý' or Name ='ÀîËÄ' Or ...Or Name='µÚÒ»°Ù¸öÐÕÃû'
......
Ôõô°ÑMDFÊý¾Ýתµ½MySQL£¿
ÖÁÉٵø½¼Óµ½sqlserverÉÏ
¾ßÌåÔõôŪ°¡ ÎҵıÏÒµÉè¼ÆµÄÊý¾Ý¿âÊÇ´ÓÍøÉÏdownÏÂÀ´µÄ£¿£¿
Ä㻹²»ÈçÖ±½ÓÓÃsqlserverÄØ
º¯Êý¡¢´æ´¢¹ý³Ì¶¼µÃ¸ÄÁË¡£
sqlserverûÔõôÓùý¡£Ò²Ã»Óа²× ......
A±í ÓÐÁ½¸ö×Ö¶Î
id ΨһÊý×ÖÓò
InfoTxt text ÀàÐÍ
ÎÒÏÖÔÚÒª°Ñ id ²»ÊÇ14 µÄËùÓÐ InfoTxt×ֶΠÎı¾ºóÃæ ¶¼¼ÓÉÏ 'aaa'
°´ÏÂÃæÖ´ÐÐÏÂÀ´ Ö»Óбí×îºóÒ»ÐмÓÉÏÁË 'aaa' ......