使用sql语句获得当前月天数
使用sql语句获得当前月天数
--获得当月天数
select day(dateadd(mm,1,getdate())-day(getdate())) as 本月天数 ;
select getdate() as 当前日期;
select day(getdate()) as 目前第几天;
select getdate()-day(getdate()) as 上个月最后一天; -- 减去了当前的天数
select dateadd(mm,1,getdate())-day(getdate()) as 加上一个月; -- 也就是这个月的最后一天
select day(dateadd(mm,1,getdate())-day(getdate())) as 获得当月天数;
相关文档:
SQL常用命令使用方法:
(1) 数据记录筛选:
sql="select * from 数据表 where 字段名=字段值 order by 字段名 [desc]"
sq ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
& ......
--通过sql企业管理器修改和删除a表中数据时会出现错误
--sql企业管理Bug,通过程序或执行sql语句更新a表数据没有问题
--添加
Insert a (FName, FCode, FOther) Values('11','2222','33')
--修改
Update a Set FName='22_Edit' Where FCode='22'
--删除
Delete a Where FCode='22'
--查看a/b表数据
Select * from a ......
有的时候我们需要一次像数据库中添加多条记录,我们可以使用下面的语句来实现:
--添加一条记录
INSERT INTO tableName(col1,col2,col3) VALUES (1,2,3)
--添加多条记录
INSERT INTO tableName(col1,col2,col3)
SELECT 3,4,5
UNION ALL
SELECT 6,7,8
--从另外的一张表中读取多条数据添加到新表中
INSERT INTO tabl ......
下面是操作步骤:
1. “服务和连接的外围应用配置“ -》“本地连接和远程连接”-》“同时使用TCP/IP和Named Pipes“;
2. “服务配置管理器”-》“网络配置”-》“SQL Express的协议“-》“IP地址”,将IpAll Tcp端口改为1433;
3. 重启服 ......