随笔分类 -  数据库编程

SQLSever,Oracle,PostgreSQL,MySQL,DB2,SQLite,MongoDB,HBase
摘要:1 ---sql server 2005 測試 塗聚文 捷為工作室,締友計算機信息技術有限公司 2 ---查找公曆節日 3 --select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@week and GooddayWeekdays=@Day and GooddayUidKey='F0FAFC87-F492-455F-B56E-3 阅读全文
posted @ 2012-09-21 11:51 ®Geovin Du Dream Park™ 阅读(1045) 评论(0) 推荐(0)
摘要:1 ---数据来源:http://topic.csdn.net/u/20100424/07/29529d9d-bc54-4877-b198-4426b4d85024.html 2 if object_id('SolarData') is not null 3 drop table SolarData 4 go 5 create table SolarData 6 ( 7 yearid int not null, 8 data char(7) not null, 9 dataint int not null 10 ) 11 --插入数据 12 inse... 阅读全文
posted @ 2012-09-17 16:20 ®Geovin Du Dream Park™ 阅读(588) 评论(0) 推荐(0)
摘要:1 --以工作日計算起始年假的計算時間範圍 2 declare @settoday smalldatetime,@birthday smalldatetime,@year varchar(10),@month varchar(10),@day varchar(10),@enddate datetime,@stardate datetime,@AnnualNumber int,@AnnualTotal int,@Surplus int 3 set @settoday='2013-05-04'--現在日期 4 set @birthday='2004-04-26' - 阅读全文
posted @ 2012-09-04 10:26 ®Geovin Du Dream Park™ 阅读(418) 评论(0) 推荐(0)
摘要:1 --添加用户:exec sp_addlogin ''用户名'',''密码'',''默认数据库名'' 2 exec sp_addlogin 'du','geovindu','hotel' 3 --使其成为当前数据库的合法用户 4 exec sp_grantdbaccess N'du' 5 --授予对自己数据库的所有权限 6 exec sp_addrolemember N'db_owner', N'du' 阅读全文
posted @ 2012-08-15 10:45 ®Geovin Du Dream Park™ 阅读(346) 评论(0) 推荐(0)
摘要:--時區時間 Local Time Zone Geovin Du 塗聚文--http://www.bigresource.com/MS_SQL-Converting-UTC-datetime-values-to-local-time-zones-XDKMI9sG.htmlSELECT GETUTCDATE()SELECT GETDATE()select CONVERT(varchar(100), GETUTCDATE(), 21)SELECT DATEDIFF(hh,'2008-05-20 20:08:01.020', '2008-05-20 16:08:01.020& 阅读全文
posted @ 2012-05-11 11:35 ®Geovin Du Dream Park™ 阅读(849) 评论(0) 推荐(0)
摘要:select EmployeesList.*,datediff(year,EmployeesList.EmployeeEnterDate,getdate()) as 'InJobTime' from EmployeesList---Geovin Du 塗聚文select EmployeesList.*,datediff(month,EmployeesList.EmployeeEnterDate,getdate()) as 'InJobTime' from EmployeesListselect EmployeesList.*,datediff(month,Emp 阅读全文
posted @ 2012-04-24 19:14 ®Geovin Du Dream Park™ 阅读(613) 评论(0) 推荐(0)
摘要:---2005附加數據庫---ATTACH DATABASE TEMPLATE---涂聚文 2012 元旦exec sp_attach_db 'Asset5','D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Asset5.mdf','D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Asset5_log.ldf'GO---列出存儲過程exec sp_stored_proceduresGO--系統視圖select * 阅读全文
posted @ 2012-01-05 14:55 ®Geovin Du Dream Park™ 阅读(458) 评论(0) 推荐(0)
摘要:---塗聚文 Geovin DuDECLARE @myid uniqueidentifierSET @myid = NEWID()SELECT CONVERT(char(255), @myid) AS 'char';GO--塗聚文 Geovin Dudeclare @allstring char(255),@AreaUid Uniqueidentifierset @AreaUid='37A1DA94-4AC6-4ED0-B96F-BA3FE6AEACC8'set @allstring= cast(@AreaUid as char(255))select @all 阅读全文
posted @ 2011-09-19 19:39 ®Geovin Du Dream Park™ 阅读(632) 评论(0) 推荐(0)
摘要:--CAST 和 CONVERT 函数 PercentageDECLARE @dec decimal(5,3), @var varchar(10),@hun decimal(5,1)set @dec=0.025set @hun=@dec*100set @var=cast(@hun as varchar(20))+'%'select @var---小數轉化為百分數函數 GetPercentageString---塗聚文 Geovin Duif exists (select * from dbo.sysobjects where id = object_id(N'[dbo] 阅读全文
posted @ 2011-09-03 18:19 ®Geovin Du Dream Park™ 阅读(642) 评论(0) 推荐(0)
摘要:---ntext數據類型字符替換 ---2011-08-21 塗聚文 深圳大運會期間,政府貼出"溫馨提示",交通管制,世界之窗周邊不充許到陽台觀看,出入憑居住證,不是身份證create table tt( sid INT IDENTITY(1,1), cont ntext )goinsert into tt(cont) values(N'fd sad fdsa 塗聚文工團 締友計算機信息技術有限公司 可能性 桔柑 ')goupdate tt set cont='fd sad fdsa 塗聚文工團 可能性 締友計算機信息技術有限公司 桔柑 ' 阅读全文
posted @ 2011-08-21 09:01 ®Geovin Du Dream Park™ 阅读(354) 评论(0) 推荐(0)
摘要:---兩個時間之差的合計DECLARE @I INTSET @I = DATEDIFF(ms,GETDATE()-RAND()*24,GETDATE())SELECT convert(varchar(10), @I/86400000) + ' Days ' + convert(varchar(10), (@I%86400000)/3600000) + ' Hours '+ convert(varchar(10), (@I%3600000)/60000) + ' Mins '+ convert(varchar(10), (@I%60000)/100 阅读全文
posted @ 2011-08-20 18:07 ®Geovin Du Dream Park™ 阅读(346) 评论(0) 推荐(0)
摘要:http://technet.microsoft.com/en-us/library/aa259215%28SQL.80%29.aspxhttp://www.sqlusa.com/bestpractices/setdefaultlanguage/http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59051http://msdn.microsoft.com/en-us/library/ms187335.aspxhttp://msdn.microsoft.com/en-us/library/aa259642%28v=sql.80%29.aspx-- 阅读全文
posted @ 2011-08-18 13:12 ®Geovin Du Dream Park™ 阅读(2583) 评论(0) 推荐(1)
摘要:--SQL Server 2000-----Calendar Table Geovin Du 涂聚文declare @start datetime,@end datetimeset @start = '2006-01-01'set @end = '2006-05-02'declare @no_of_Days intset @no_of_days = datediff(dd,@start,@end) + 1set rowcount @no_of_daysselect identity(int,0,1) as dy into #temp from sysobject 阅读全文
posted @ 2011-08-18 12:33 ®Geovin Du Dream Park™ 阅读(408) 评论(0) 推荐(0)
摘要:--返回第幾周DECLARE @Dt datetimeSELECT @Dt='2008-02-21'SELECT DATEPART( wk, @Dt)SELECT DATEPART( wk, GETDATE())SELECT DATEPART(weekday, GETDATE())SELECT * FROM WorkAttendanceReportSELECT [dbo].[GetWeekName] (WorkAttendanceDatetime) FROM WorkAttendanceReport---WorkAttendanceDatetimedeclare @Date s 阅读全文
posted @ 2011-08-15 18:42 ®Geovin Du Dream Park™ 阅读(2613) 评论(3) 推荐(0)
摘要:---得到遲到多少時間或沒有遲到 Geovin Du 塗聚文declare cursor_select cursor for select WorkingHoursTime,WorkingHoursUidKey FROM WorkingHoursSetdeclare @ntime smalldatetime,@uidkey Uniqueidentifier,@timeint int,@empoyee Uniqueidentifier,@WorkAttendanceUid Uniqueidentifier--set @uidkey='E0ABDEC2-4BC9-49CB-85EE-E6E 阅读全文
posted @ 2011-08-10 12:37 ®Geovin Du Dream Park™ 阅读(870) 评论(0) 推荐(0)
摘要:---會計記賬 Debit-Credit BookkeepingCREATE TABLE #geovindu ( Account VARCHAR(20), --賬號 [Date] DATETIME, --時間 Debit DECIMAL(9,2), --借入 Credit DECIMAL(9,2) --貸出) GOINSERT INTO #geovindu VALUES ('10139', '2007-08-31', 2025.91, 0.0) INSERT INTO #geovindu VALUES ('10139', '2007-08 阅读全文
posted @ 2011-07-23 12:19 ®Geovin Du Dream Park™ 阅读(436) 评论(0) 推荐(0)
摘要:---SQL SERVER 2000 遍历父子关系數據表(二叉树)获得所有子节点 所有父节点及节点层数函数---Geovin Du 涂聚文--建立測試環境Create Table GeovinDu([ID] Int, fatherID Int, [Name] Varchar(10))Insert A Select 1, 0, '中国'Union All Select 2, 1, '广东'Union All Select 3, 1, '北京'Union All Select 4, 2, '深圳特区'Union All Select 阅读全文
posted @ 2011-07-12 16:12 ®Geovin Du Dream Park™ 阅读(1019) 评论(0) 推荐(0)
摘要:--sql server 2005 输出表的函數用法--Geovin Du 塗聚文 --締友計算機信息技術有限公司create function EmailParse (@email varchar(1000))returns @t table (UserName varchar(20), Domain varchar(20))asbegin declare @i int select @i = charindex('@', @email,1); if (@i > 1) insert into @t values (left(@email,@i-1), substring 阅读全文
posted @ 2011-07-08 15:58 ®Geovin Du Dream Park™ 阅读(370) 评论(0) 推荐(0)
摘要:--SQL server 2005 表中某一字段的所有值逗号分开的列表Geovin Du 塗聚文select * from Production.Productdeclare @names varchar(50)set @names=''select @names=@names+s.Name+' , 'from Production.Product sorder by s.Nameselect @namesgo--sql server 2000 如何逐条读出表中某一字段的所有值 Geovin Du 塗聚文declare @allstring varchar(80 阅读全文
posted @ 2011-07-08 08:37 ®Geovin Du Dream Park™ 阅读(418) 评论(0) 推荐(0)
摘要:SQL Server 2000 http://msdn.microsoft.com/en-us/library/Aa223952http://msdn.microsoft.com/en-us/library/aa902644(SQL.80).aspxhttp://msdn.microsoft.com/en-us/library/aa902644(SQL.80).aspx#intlfeaturesinsqlserver2000_usingadpformatSQL Server 2005 http://msdn.microsoft.com/zh-cn/library/ms188688(v=sql. 阅读全文
posted @ 2011-07-04 18:26 ®Geovin Du Dream Park™ 阅读(354) 评论(0) 推荐(0)