随笔分类 -  数据库编程

SQLSever,Oracle,PostgreSQL,MySQL,DB2,SQLite,MongoDB,HBase
摘要:---1.以日期字符操作转换日期 如果是VIP1生日不对,可以以上传的数据日期为生日begindeclare @NowBirthday datetime, @birthday datetime,@stat datetime,@end datetime,@statbirthday datetime,... 阅读全文
posted @ 2014-07-17 15:35 ®Geovin Du Dream Park™ 阅读(437) 评论(0) 推荐(0)
摘要:--查询权限函数--1declare @names varchar(3000)set @names=''select @names=@names+isnull(AdminPermissFormName,'')+' , ' from BookAdminPermissTypeList where Ad... 阅读全文
posted @ 2014-06-20 18:21 ®Geovin Du Dream Park™ 阅读(366) 评论(0) 推荐(0)
摘要:---使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式select * from BookInfoList--存在不同的select BookInfoID,BookInfoBarCode from BookInfoList where ... 阅读全文
posted @ 2014-06-12 11:28 ®Geovin Du Dream Park™ 阅读(493) 评论(0) 推荐(0)
摘要:http://www.mssqltips.com/sqlservertip/1738/sql-server-udf-to-pad-a-string/declare @l varchar(50)set @l='3 'select @l=ltrim(rtrim('3'))select len(@l)SE... 阅读全文
posted @ 2014-05-16 12:46 ®Geovin Du Dream Park™ 阅读(557) 评论(0) 推荐(0)
摘要:--显示所有用户表:--1SELECT SCHEMA_NAME(schema_id) As SchemaName , name As TableName from sys.tables ORDER BY name--2。alternate:SELECT sch.name As Schem... 阅读全文
posted @ 2014-05-15 22:59 ®Geovin Du Dream Park™ 阅读(1160) 评论(0) 推荐(0)
摘要:--无法解决 equal to 操作中 "Chinese_PRC_CI_AS" 和 "Chinese_Taiwan_Stroke_CI_AS" 之间的排序规则冲突。CREATE VIEW View_VipBranchStaffBranchListASselect VipBranchStaff.*,geovindu_branch.B_Name,VipExamCountry.ExamCountryName from VipBranchStaff,geovindu_branch,VipExamCountry where VipBranchStaff.Branc 阅读全文
posted @ 2014-02-24 12:01 ®Geovin Du Dream Park™ 阅读(5806) 评论(0) 推荐(0)
摘要:T-SQL:declare @int int,@prov int,@city int,@str nvarchar(500)set @str='天河麗特青春:中國廣東省廣州市天河區天河路623號天河娛樂廣場麗特青春百貨一樓,塗聚文'select @int=charindex(':',@str) select @prov=charindex('省',@str) select @city=charindex('市',@str) select substring(@str,0,@int)select substring(@str,@int 阅读全文
posted @ 2014-02-21 15:13 ®Geovin Du Dream Park™ 阅读(741) 评论(0) 推荐(0)
摘要:---Example Uses of the SUBSTRING String Function--http://www.sql-server-helper.com/tips/tip-of-the-day.aspx?tkey=4AB06421-E859-4B5F-A948-0C9640F3108D&tkw=sample-uses-of-the-substring-string-function--取名字Usage #1 : Get the First Name and Last Name from a Full NameDECLARE @FullName VARCHAR(50) --s 阅读全文
posted @ 2014-01-21 12:09 ®Geovin Du Dream Park™ 阅读(404) 评论(0) 推荐(0)
摘要:DECLARE @birthday datetime,@stat datetime,@end datetime,@statbirthday datetime,@endbirthday datetime,@thirdbirthday datetime,@firthbirthday datetime, @year int,@month int , @day int,@str varchar(20),@total int,@firthmonth int,@thirmonth int,@now datetime,@vipno nvarchar(10) --参数set @vipno='88888 阅读全文
posted @ 2013-12-02 15:12 ®Geovin Du Dream Park™ 阅读(472) 评论(0) 推荐(0)
摘要:---2013年10月9日生日,就以2012年9月1日至2013年8月31日計算 (因為係生日月份前兩個月之最後一天為結算日)DECLARE @birthday datetime,@now datetime,@stat datetime,@end datetime,@statbirthday datetime,@endbirthday datetime,@thirdbirthday datetime,@firthbirthday datetime, @year int,@month int , @day int,@str varchar(20),@total decimalset @now.. 阅读全文
posted @ 2013-10-29 10:25 ®Geovin Du Dream Park™ 阅读(439) 评论(0) 推荐(0)
摘要:drop table t_geovinducreate table t_geovindu( xid int IDENTITY (1, 1), price money, DebitCredit VARCHAR(2), adate datetime default(getdate()) )insert into t_geovindu(DebitCredit,price) values('C',10)insert into t_geovindu(DebitCredit,price) values('C',25)insert into t_geovindu(DebitC 阅读全文
posted @ 2013-08-05 17:01 ®Geovin Du Dream Park™ 阅读(675) 评论(0) 推荐(0)
摘要:--這種是無效的過程 declare @sql nvarchar(500), @where nvarchar(500),@i nvarchar(64),@p nvarchar(50),@id intset @id=5set @sql='select '+@p+'=AreaCode from AdministrativeAreaList where AreaID='+cast(@id as varchar)--select @sqlexec @sql--測試結果:未能找到存储过程 ''。---sql server 2000/2005 塗聚文 201 阅读全文
posted @ 2013-07-16 10:00 ®Geovin Du Dream Park™ 阅读(587) 评论(1) 推荐(0)
摘要:---sql server declare @date datetimeset @date='2012-02-03'--getdate()--本月第一天SELECT DATEADD(mm, DATEDIFF(mm,0,@date), 0)--本月最后一天SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,@date)+1, 0))---有個月多少天函數if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetAMonthHowNumber]&# 阅读全文
posted @ 2013-05-29 09:28 ®Geovin Du Dream Park™ 阅读(908) 评论(0) 推荐(0)
摘要:---sql server 2005 顯示一個月的數據,如果沒有空的也要顯示出來declare @T table([geovinddate] Datetime,[workcontent] nvarchar(8),[worker] nvarchar(50))Insert @Tselect '2012-8-11',N'遲到','geovindu' union allselect '2012-8-12',N'早退','geovin';with Dateas(select cast('2012-08 阅读全文
posted @ 2013-05-22 15:05 ®Geovin Du Dream Park™ 阅读(326) 评论(0) 推荐(0)
摘要:1 ---請假跨月份問題,或跨年份問題 日期部分边界 2 declare @sart datetime,@end datetime,@d int,@s1 datetime,@e1 datetime,@s2 datetime,@e2 datetime,@t varchar(50),@t2 varchar(50),@I int 3 set @sart='2012-11-18 14:56:12' 4 set @end='2012-12-08 14:56:12' 5 --set @I=DATEDIFF(ms,@sart,@end) 6 set @I=DATEDIFF(s 阅读全文
posted @ 2013-04-11 11:25 ®Geovin Du Dream Park™ 阅读(699) 评论(0) 推荐(0)
摘要:http://www.wiseowl.co.uk/blog/s334/calendar.htmSQL Server 2012 1 CREATE PROC spCreateCalendarTable( 2 @StartDate datetime = '20000101', 3 @EndDate datetime = '20201231' 4 ) AS 5 6 -- create a table of dates for use in PowerPivot 7 8 -- NOT FOR COMMERCIAL USE OR REDISTRIBUTION 9 -- WI 阅读全文
posted @ 2013-03-06 10:32 ®Geovin Du Dream Park™ 阅读(420) 评论(0) 推荐(0)
摘要:1 --日曆(sql server 2005) 2 3 CREATE TABLE T1 (ID INTEGER) 4 INSERT INTO T1 VALUES (1) 5 ---- 6 with x(dy,dm,mth,dw,wk) 7 as( 8 select dy, 9 day(dy) dm,10 datepart(m,dy) mth,11 datepart(dw,dy) dw, 12 case when datepart(dw,dy)=113 then datepart(ww,dy)-114 ... 阅读全文
posted @ 2013-03-04 18:06 ®Geovin Du Dream Park™ 阅读(368) 评论(0) 推荐(0)
摘要:1 ---去除字符串中重復的值函數 2 create function StringRemove(@str nvarchar(2000)) 3 returns nvarchar(2000) 4 as 5 begin 6 declare @result nvarchar(2000),@temp nvarchar(1000) 7 set @result='' 8 set @temp='' 9 while(charindex(',',@str)<>0)10 begin11 set @temp=substring(@str,1,... 阅读全文
posted @ 2013-01-19 17:17 ®Geovin Du Dream Park™ 阅读(470) 评论(0) 推荐(0)
摘要:---表中的主鍵select [name],'tablekey'= (select top 1 COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = sysobjects.name) from sysobjects where type='U'--所有表select * from sysobjects where type='U'--所有表的主鍵 COLUMN_NAMEselect * from INFORMATION_SCHEMA.KEY_COLUMN_U 阅读全文
posted @ 2012-12-27 19:18 ®Geovin Du Dream Park™ 阅读(477) 评论(0) 推荐(0)
摘要:---沒有去除重復的記錄select distinct ContractLaborEmployeeUidKey,ContractLaborEndDate from ContractLaborList order by ContractLaborEndDate descselect * from ContractLaborList order by ContractLaborEmployeeUidKey---沒有去除重復的記錄select * from ContractLaborList where ContractLaborEmployeeUidKey in (select distinct. 阅读全文
posted @ 2012-10-31 19:18 ®Geovin Du Dream Park™ 阅读(246) 评论(0) 推荐(0)