SQL 获取当前日期,年、月、日、周、时、分、秒
select GETDATE() as '当前日期',
DateName(year,GetDate()) as '年',
DateName(month,GetDate()) as '月',
DateName(day,GetDate()) as '日',
DateName(dw,GetDate()) as '星期',
DateName(week,GetDate()) as '周数',
DateName(hour,GetDate()) as '时',
DateName(minute,GetDate()) as '分',
DateName(second,GetDate()) as '秒'
结果:
2009-12-19 15:23:50.530 2009 12 19 星期六 51 15 23 50
相关文档:
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......
1。select * from v$nls_parameters
查询nls的参数,获得数据库服务器端的字符编码
NLS_LANGUAGE
NLS_CHARACTERSET
2。修改本地环境变量,设置
NLS_LANG = SIMPLIFIED CHINESE.ZHS16GBK //这个是我们的数据库字符编码
NLS_LANG格式:
NLS_LANG = language_territory.char ......
1、Datediff:
1.1算出日期差:
1.access: datediff('d',fixdate,getdate())
2.sqlserver: datediff(day,fixdate,getdate())
ACCESS实例: select * from table where data=datediff('d',fixdate,getdate())
sqlserver实例: select * from ......
1、SELECT 查询语句和条件语句
SELECT 查询字段 from 表名 WHERE 条件
查询字段:可以使用通配符* 、字段名、字段别名
表名: 数据库.表名 ,表名
常用条件: = 等于 、<>不等于、in 包含 、 not in 不包含、 like 匹配
BETWEEN 在范围 、 not BETWEE ......
表如下
一条语句显示所有大于25岁和下的人,以上的人显'大龄'
select case when age>25 then '大龄' else '小龄' end as 年龄级别,count(*) as 人数 from infor group by case when age>25 then '大龄' else '小龄' end
......