Billpeng Space

技术源自生活
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  SQL

摘要:delete WeiBoTopics where Id in(select max(Id) from WeiBoTopics group by WeiBoId,Title having COUNT(*) > 1); 阅读全文

posted @ 2015-04-20 15:38 billpeng 阅读(186) 评论(0) 推荐(0)

摘要:1.round() 函数是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位。 2.numeric 函数的2个参数,第一个表示数据长度,第二个参数表示小数点后位数。 例如: select cast(round(12.5,2) as numeric(5,2)) 结果:12.50 select cast(round(12.555,2) as numeric(5,2)) 结果:12.56 select cast(round(122.5255,2) as numeric(5,2))结果:122.53 select cast(round(1222... 阅读全文

posted @ 2012-08-27 15:37 billpeng 阅读(142595) 评论(0) 推荐(3)

摘要:alter table bbsmessage add quoteMessage varchar(2000) default '' 阅读全文

posted @ 2012-08-14 13:41 billpeng 阅读(312) 评论(0) 推荐(0)

摘要:select max(rowcnt) from sysindexes where id=object_id('foodstuff') 阅读全文

posted @ 2012-06-17 01:34 billpeng 阅读(192) 评论(0) 推荐(0)

摘要:select count(*) from (select GameScore.gameid from GameScore where GameScore.Username <> '' Group by GameScore.Username, GameScore.gameid) as a; 阅读全文

posted @ 2011-10-07 22:39 billpeng 阅读(1440) 评论(0) 推荐(0)

摘要:declare@viewnamevarchar(250),@idint,@textvarchar(8000)declare#aacursorforselectid,namefromsysobjectswhereobjectproperty(id,'IsView')=1anduid=1andleft(name,3)<>'sys'open#aafetchnextfrom#aainto@id,@viewnamewhile@@fetch_status=0beginselect@text=''select@text=@text+char(13) 阅读全文

posted @ 2011-04-02 09:21 billpeng 阅读(668) 评论(2) 推荐(0)

摘要:在.net中操作数据库的时候。 大家都喜欢用sqlparameter。 parameter是预编译的,可以加快速度,也可以防注入。 在使用mssql的时候用sqlparameter。 在使用mysql的时候使用mysqlparameters。 第一次使用mysql的时候,都经常犯一个错误 比如在使用mssql的时候,一条查询这么写 select name,id from user where id... 阅读全文

posted @ 2010-10-26 12:18 billpeng 阅读(430) 评论(0) 推荐(0)

摘要:[代码] 阅读全文

posted @ 2010-08-17 22:46 billpeng 阅读(695) 评论(0) 推荐(0)

摘要:select top 10 * from userinfo order by NEWID() 阅读全文

posted @ 2010-08-08 16:23 billpeng 阅读(307) 评论(0) 推荐(0)

摘要:http://database.ctocio.com.cn/tips/272/7588272.shtml 阅读全文

posted @ 2010-04-02 22:47 billpeng 阅读(243) 评论(0) 推荐(0)

摘要:如果我们想对一个表的每一行做出比较复杂的操作,大多会想到用游标,本文中,我们将换一种思路,用SQL Server 2005中的新函数ROW_NUMBER()和while循环来对每一行执行操作。详细的示例代码如下: select Department_No as departmentNo,ROW_NUMBER() OVER(ORDER BY Department_No) AS rowNumber i... 阅读全文

posted @ 2010-03-28 10:44 billpeng 阅读(250) 评论(0) 推荐(1)

摘要:select t.* from GameScore t where id in(select top 3 id from GameScore where GameID=t.GameID order by Score desc) order by Score desc 阅读全文

posted @ 2009-09-10 15:33 billpeng 阅读(1151) 评论(0) 推荐(0)

摘要:本周:select * from table where datediff(week,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段 本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0--C_CALLTIME 为日期字段 本季:select * from table where... 阅读全文

posted @ 2009-09-08 14:34 billpeng 阅读(214) 评论(0) 推荐(1)

摘要:一、查找重复记录1。查找全部重复记录Select * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)2。过滤重复记录(只显示一条)Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)注:此处显示ID最大一条记录二、删除重复记录1。删除全部重复记录(慎用)Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)> 阅读全文

posted @ 2009-06-24 10:34 billpeng 阅读(689) 评论(0) 推荐(0)

摘要:[代码] 阅读全文

posted @ 2009-05-21 14:15 billpeng 阅读(361) 评论(0) 推荐(0)

摘要:在SQL2000中,Select Top后是不能直接更变量的 阅读全文

posted @ 2009-02-25 12:00 billpeng 阅读(500) 评论(0) 推荐(0)

摘要:使用方法: select dbo.MD5('admin') as adminField 阅读全文

posted @ 2009-02-08 20:00 billpeng 阅读(531) 评论(0) 推荐(0)

摘要:Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->select * from UserInfo where DATEDIFF([year], Birthday, GETDATE()) >= 28--Birthday为数据库中的生日,28为年龄 阅读全文

posted @ 2009-02-01 19:18 billpeng 阅读(366) 评论(0) 推荐(0)

摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--DECLARE@tempFriendvarchar(5000)DECLARErsCURSORLOCALSCROLLFORselectFriendfromFriendwhereUsername=@UsernameOPENrsFETCHNEXTFROMrsINTO@tempFriend--循环WHILE@@FETCH_STATUS=0BEGINSET@Friend=@Friend+@tempFrien 阅读全文

posted @ 2009-01-28 23:31 billpeng 阅读(696) 评论(0) 推荐(0)

摘要:RETURN只能返回INT型,OUTPUT可以返回自定义类型 执行到RETURN的时候存储过程即结束。 而OUTPUT的变量可以重复设置 阅读全文

posted @ 2009-01-23 00:37 billpeng 阅读(1460) 评论(0) 推荐(1)