--------------------SQL Server数据格式化工具------------------- --------------------------------------------------------------- -- DESIGNER :happycell188(喜喜) -- QQ :584738179 -- Development Tool :Microsoft Visual C++ 6.0 C Language -- FUNCTION :CONVERT DATA TO T-SQL --------------------------------------------------------------- -- Microsoft SQL Server 2005 -- Developer Edition on Microsoft Windows XP [版本 5.1.2600] --------------------------------------------------------------- ---------------------------------------------------------------use test go if object_id('test.dbo.tb') is not null drop table tb -- 创建数据表 create table tb ( 学号 char(8), 姓名 char(5), 性别 char(3) ) go --插入测试数据 insert into tb select '0310101','张三','男' union all select '0310102','李四','男' union all select '0310103','王五','女' go --代码实现alter table tb add 出生日期 datetime null go ;with t as (select idd=row_number()over(order by getdate()),* from tb) update tb set 出生日期=date from ( select idd=row_number()over(order by getdate()),* from (select date='1982-05-12' union all select '1985-12-25' union all select '1983-10-1' )t )tt inner join t on tt.idd=t.idd--> 显示结果select * from tb /*测试结果学号 姓名 性别 出生日期 ----------------------------------------------------- 0310101 张三 男 1982-05-12 00:00:00.000 0310102 李四 男 1983-10-01 00:00:00.000 0310103 王五 女 1982-05-12 00:00:00.000(3 行受影响) */ '这样成不??'
--------------------SQL Server数据格式化工具------------------- --------------------------------------------------------------- -- DESIGNER :happycell188(喜喜) -- QQ :584738179 -- Development Tool :Microsoft Visual C++ 6.0 C Language -- FUNCTION :CONVERT DATA TO T-SQL --------------------------------------------------------------- -- Microsoft SQL Server 2005 -- Developer Edition on Microsoft Windows XP [版本 5.1.2600] --------------------------------------------------------------- ---------------------------------------------------------------use test go if object_id('test.dbo.tb') is not null drop table tb -- 创建数据表 create table tb ( 学号 char(8), 姓名 char(5), 性别 char(3) ) go --插入测试数据 insert into tb select '0310101','张三','男' union all select '0310102','李四','男' union all select '0310103','王五','女' go --代码实现alter table tb add 出生日期 varchar(20) null go set quoted_identifier off ;with t as (select idd=row_number()over(order by getdate()),* from tb) update tb set 出生日期=date from ( select idd=row_number()over(order by getdate()),* from (select date="N'1982-05-12'" union all select "N'1985-12-25'" union all select "N'1983-10-1'" )t )tt inner join t on tt.idd=t.idd--> 显示结果select * from tb /*测试结果学号 姓名 性别 出生日期 ----------------------------------------------------- 0310101 张三 男 N'1982-05-12' 0310102 李四 男 N'1983-10-1' 0310103 王五 女 N'1982-05-12'(3 行受影响) */ '还是这样??'
就是这样一个表
学号 姓名 性别
0310101 张三 男
0310102 李四 男
0310103 王五 女
.....
然后我想在原来表的基础上增加一个[出生日期,datetime]字段
然后通过语句对该字段赋值N'1982-05-12',N'1985-12-25',N'1983-10-1'
就是这样了
烦请大家给一个测试通过的语句
谢谢了。
---------------------------------------------------------------
-- DESIGNER :happycell188(喜喜)
-- QQ :584738179
-- Development Tool :Microsoft Visual C++ 6.0 C Language
-- FUNCTION :CONVERT DATA TO T-SQL
---------------------------------------------------------------
-- Microsoft SQL Server 2005
-- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
---------------------------------------------------------------
---------------------------------------------------------------use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
学号 char(8),
姓名 char(5),
性别 char(3)
)
go
--插入测试数据
insert into tb select '0310101','张三','男'
union all select '0310102','李四','男'
union all select '0310103','王五','女'
go
--代码实现alter table tb add 出生日期 datetime null
go
;with t as (select idd=row_number()over(order by getdate()),* from tb)
update tb set 出生日期=date from (
select idd=row_number()over(order by getdate()),*
from (select date='1982-05-12'
union all select '1985-12-25'
union all select '1983-10-1' )t
)tt inner join t on tt.idd=t.idd--> 显示结果select * from tb
/*测试结果学号 姓名 性别 出生日期
-----------------------------------------------------
0310101 张三 男 1982-05-12 00:00:00.000
0310102 李四 男 1983-10-01 00:00:00.000
0310103 王五 女 1982-05-12 00:00:00.000(3 行受影响)
*/
'这样成不??'
---------------------------------------------------------------
-- DESIGNER :happycell188(喜喜)
-- QQ :584738179
-- Development Tool :Microsoft Visual C++ 6.0 C Language
-- FUNCTION :CONVERT DATA TO T-SQL
---------------------------------------------------------------
-- Microsoft SQL Server 2005
-- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
---------------------------------------------------------------
---------------------------------------------------------------use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
学号 char(8),
姓名 char(5),
性别 char(3)
)
go
--插入测试数据
insert into tb select '0310101','张三','男'
union all select '0310102','李四','男'
union all select '0310103','王五','女'
go
--代码实现alter table tb add 出生日期 varchar(20) null
go
set quoted_identifier off
;with t as (select idd=row_number()over(order by getdate()),* from tb)
update tb set 出生日期=date from (
select idd=row_number()over(order by getdate()),*
from (select date="N'1982-05-12'"
union all select "N'1985-12-25'"
union all select "N'1983-10-1'" )t
)tt inner join t on tt.idd=t.idd--> 显示结果select * from tb
/*测试结果学号 姓名 性别 出生日期
-----------------------------------------------------
0310101 张三 男 N'1982-05-12'
0310102 李四 男 N'1983-10-1'
0310103 王五 女 N'1982-05-12'(3 行受影响)
*/
'还是这样??'