select year(getdate()+7),month(getdate()+7),day(getdate()+7)
Union all
select year(getdate()+8),month(getdate()+8),day(getdate()+8)
Union all
select year(getdate()+9),month(getdate()+9),day(getdate()+9)select year(getdate()+7),month(getdate()+7),day(getdate()+7)
Union all
select year(getdate()+8),month(getdate()+8),day(getdate()+8)
Union all
select year(getdate()+9),month(getdate()+9),day(getdate()+9)
----------- ----------- -----------
2004 1 7
2004 1 8
2004 1 9(所影响的行数为 3 行)
Union all
select year(getdate()+8),month(getdate()+8),day(getdate()+8)
Union all
select year(getdate()+9),month(getdate()+9),day(getdate()+9)select year(getdate()+7),month(getdate()+7),day(getdate()+7)
Union all
select year(getdate()+8),month(getdate()+8),day(getdate()+8)
Union all
select year(getdate()+9),month(getdate()+9),day(getdate()+9)
----------- ----------- -----------
2004 1 7
2004 1 8
2004 1 9(所影响的行数为 3 行)
解决方案 »
- 如何SQL Server 2005 设置字符集为UTF-8?
- sqlserver2000,怎样记录一数据库中创建的新表?
- 2张表的更新的sql语句问题 谢谢
- 为何又是大于,又是小于的,不前后矛盾吗?
- 关于错误提示“将截断字符串或二进制数据”的问题
- SQL server创建函数报错误,大家帮助我看看什么问题
- 我想删除主键,同时删除外键的内容
- 如何把sql server数据库导出成vfp的dbf表?
- reporting service 数据库身份验证
- 可不可以写在Insert前发生的触发器
- 在企业管理器里误打了 Delete From tablename 后有办法后悔吗?
- 请问网上过六级的好网站有哪此啊?
Union all
select year(getdate()+8),month(getdate()+8),day(getdate()+8)
Union all
select year(getdate()+9),month(getdate()+9),day(getdate()+9)
----------- ----------- -----------
2004 1 7
2004 1 8
2004 1 9(所影响的行数为 3 行)
from # where id>=7 and id<=datediff(dy,getdate(),'2005-12-31')
from # where id>=7 and id<=datediff(dy,getdate(),'2005-12-31')
yy mm dd
----------- ----------- -----------
2004 1 7
2004 1 8
2004 1 9
2004 1 10
.....
2005 12 28
2005 12 29
2005 12 30
2005 12 31(所影响的行数为 725 行)
union all
select year(getdate()) as nyear,month(getdate()) as nmonth, day(getdate()+8) as nday
union all
select year(getdate()) as nyear,month(getdate()) as nmonth, day(getdate()+9) as nday
select datepart(year,getdate()),datepart(month,getdate()),datepart(day,getdate(+7)
union all
select datepart(year,getdate()),datepart(month,getdate()),datepart(day,getdate(+8)
union all
select datepart(year,getdate()),datepart(month,getdate()),datepart(day,getdate(+9)
create function dbo.f_getid()
returns int
as
begin
declare @id int
select @id=max(tmpid) from table1
set @id=isnull(@id,0)+1
return(@id)
end
go
--建立表
create table table1 (
MyYear varchar(100) default year(dateadd(day,dbo.f_getid(),getdate()))
,MyMonth varchar(100) default month(dateadd(day,dbo.f_getid(),getdate())),
MyDay varchar(100) default day(dateadd(day,dbo.f_getid(),getdate())) ,tmpid int)
--测试插入值
declare @j int
set @j=7
while @j<datediff(day, getdate(),'2005-2-2')+7 begin
insert into table1 (tmpid) values (@j)
set @j=@j+1
end
select * from table1
--删除测试环境
drop table table1
drop function f_getid
day(dateadd(day,id,getdate())) 日
from # where id<=datediff(day,getdate(),'2005-12-31')
drop table #所影响的行数为 1500 行)id 年 月 日
----------- ----------- ----------- -----------
7 2004 1 7
8 2004 1 8
9 2004 1 9
10 2004 1 10
11 2004 1 11
12 2004 1 12
13 2004 1 13
14 2004 1 14
15 2004 1 15
16 2004 1 16
17 2004 1 17
select year(getdate()+id) yy,month(getdate()+id) mm,day(getdate()+id) dd
from # where id>=7 and id<=datediff(dy,getdate(),'2005-12-31')
不行啊:
服务器: 消息 4508,级别 16,状态 1,过程 sss,行 3
不允许在临时表上建立视图或函数。以 '#' 开头的表名表示临时表。
MSSQL MONTH(), DAY(), YEAR()作用后都是省0的.
right(('0'+cast(month(getdate()+nid) as nvarchar)),2) mm,
right(('0'+cast(day(getdate()+nid) as nvarchar)),2) dd
from temptable where nid>=7 and nid<=datediff(dy,getdate(),'2005-12-31')------------------------------------------
(所影响的行数为 1500 行)
(所影响的行数为 725 行)
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05 101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM