sql ֪ʶ
select datediff(month,'2009-11-02','2009-12-01')
²»ÖªµÀÄãÒªÔõô¸öÔ²îÒì
ÉÏÃæµÄÃüÁî½á¹ûÒ²ÊÇ1
µ«ÊÇÆäʵ°´ÕÕ³£Ê¶²îÒì²»ÊÇÒ»¸öÔ£¬ÊDzîÒ»ÌìÒ»¸öÔÂ
ÕâÓжÎÏֳɵĴúÂë¿ÉÒÔ°ïÖúÄãËã³ö³£Ê¶ÉϵIJîÒì
SQL code
declare @t table(a datetime,b datetime);
insert @t
select '2009-11-02','2009-12-01' UNION ALL
select '2009-11-01','2009-12-01'
-->??
select a,b,
ltrim(case
when (month(b)=month(a) and day(b)>=day(a)) or month(b)>month(a)
then datediff(year,a,b)
else
datediff(year,a,b)-1
end)+'Äê'
+ltrim(case
when day(b)>=day(a) --and month(b)>=month(a)
then datediff(month,a,b)%12
else
(datediff(month,a,b)-1)%12
end)+'ÔÂ'
+ltrim(case
when day(b)>=day(a)
then day(b)-day(a)
else
datediff(dd,convert(varchar(8),dateadd(mm,-1,b),120)+'01',b)+1-day(a)
end)+'ÈÕ' as 'ÈÕÆÚ²î'
from
(select (case when a>b then b else a end) as a,
(case when a>b then a else b end) as b from @t ) t;
a b ÈÕÆÚ²î
2009-11-02 00:00:00.000 2009-12-01 00:00:00.000 0Äê0ÔÂ29ÈÕ
2009-11-01 00:00:00.000 2009-12-01 00:00:00.000 0Äê1ÔÂ0ÈÕ
Ïà¹ØÎĵµ£º
ÅäÖÃʹÓà SQL ServerÌṩ³ÌÐò
<configuration>
<system.web> <-- ¸ü¸ÄÌṩ³ÌÐòÅäÖ㺠-->
<membership defaultProvider="AspNetSqlProvider" />
</system.web>
<membership> <--ÅäÖÃÌṩ³ÌÐò -->
<prov ......
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
1. Èç¹ûÄãÏ£ÍûʹÓÃselcet topÓï¾ä£¬²¢ÇÒ»¹Òª¸½´øwhereÌõ¼þ£¬ÄÇôÌõ¼þÖеÄÁо͵ÃÊǺÏÊʵÄË÷Òý£¬Èç¾Û¼¯Ë÷Òý¡¢¸´ºÏË÷ÒýÀïµÄÖ÷ÁÐ
µÈ£¬Í¬Ê±£¬whereÌõ¼þÀïÒ²Òª¾¡Á¿±Ü¿ªÊ¹Óú¯Êý£¬or£¬ÅжÏNULLµÈ»áÒýÆðÈ«²¿É¨ÃèµÄÓï¾ä£¬²»È»Ö´ÐеÄÊÇÈ«±íɨÃè¡£
2. ͨ¹ýÉèÖÃSTATISTICSÎÒÃÇ¿ÉÒԲ鿴ִÐÐSQLʱµÄÖ´ÐÐЧÂÊÒÔ¼°Ïà¹ØÐÔÄܲâÊÔ ......
1:Ó¦ÓóÌÐò²»ÔÙÐèҪʹÓà Class.forName() ÏÔʽµØ¼ÓÔØ JDBC Çý¶¯³ÌÐò¡£µ±Ç°Ê¹Óà Class.forName() ¼ÓÔØ JDBC Çý¶¯³ÌÐòµÄÏÖÓгÌÐò½«ÔÚ²»×÷Ð޸ĵÄÇé¿öϼÌÐø¹¤×÷¡£
2:ÐèҪעÒâÒÔÏÂÃüÁ
executeUpdate£ºÊÇ×î»ù´¡µÄÊý¾Ý¿âµÄ¸üС¢²åÈëºÍɾ³ý²Ù×÷¡£Ð§ÂʵÍÏ¡£
executeQuery£ºÊÇ×î»ù´¡µÄÖ´ÐвéѯÓï¾ä£¬Í¬Ñù ......
Êý¾Ý¿âsqlÓï¾äϵÁж¼ÊÇÒÔÏÂÃæµÄ±íΪ»ù´¡µÄ
1. д³ö²½Öè4Öеĸ÷Ïî²Ù×÷µÄSQLÓï¾ä¡£
¢Ù ¸øѧÉú±íÔö¼ÓÒ»ÊôÐÔNation£¨Ãñ×壩£¬Êý¾ÝÀàÐÍΪVarchar£¨20£©£»
alter table Student add Nation varchar(20);
¢Ú ɾ³ýѧÉú±íÖÐÐÂÔöµÄÊôÐÔNation£»
alter table Student DR ......