源表T
"单据编号" "航班计划日期" "航班号" "起飞航站代码" "降落航站代码"
"C-026413700" "2013-2-11" "CA1231" "PEK" "XIY"
"C-026413699" "2013-2-11" "CA1231" "PEK" "XIY"
"C-026413698" "2013-2-11" "CA1231" "PEK" "XIY"
"C-026413697" "2013-2-11" "CA1231" "PEK" "XIY"
"C-026413696" "2013-2-11" "CA1231" "PEK" "XIY"
目标表T:
单据编号 航班计划日期 航班号 起飞航站代码 降落航站代码
C-026413700 2013-2-11 CA1231 PEK XIY
C-026413699 2013-2-11 CA1231 PEK XIY
C-026413698 2013-2-11 CA1231 PEK XIY
C-026413697 2013-2-11 CA1231 PEK XIY
C-026413696 2013-2-11 CA1231 PEK XIY
SQL语句:
--如果数据库中存在 表T,则删除表T
if not object_id(N'T') is null
drop table T
Go
--新建表T
Create table T(["单据编号"] nvarchar(33),["航班计划日期"] nvarchar(31),["航班号"] nvarchar(28),["起飞航站代码"] nvarchar(25),["降落航站代码"] nvarchar(25))
SELECT * FROM dbo.T
--新增数据
Insert T
select N'"C-026413700"',N'"2013-2-11"',N'"CA1231"',N'"PEK"',N'"XIY"' union all
select N'"C-026413699"',N'"2013-2-11"',N'"CA1231"',N'"PEK"',N'"XIY"' union all
select N'"C-026413698"',N'"2013-2-11"',N'"CA1231"',N'"PEK"',N'"XIY"' union all
select N'"C-026413697"',N'"2013-2-11"',N'"CA1231"',N'"PEK"',N'"XIY"' union all
select N'"C-026413696"',N'"2013-2-11"',N'"CA1231"',N'"PEK"',N'"XIY"'
Go
SELECT * FROM dbo.T
--更新表T中数据:将数据中 双隐号 删除
UPDATE T
SET ["单据编号"] = REPLACE(["单据编号"], '"', '') ,
["航班计划日期"] = REPLACE(["航班计划日期"], '"', ''),
["航班号"] = REPLACE(["航班号"], '"', ''),
["起飞航站代码"] = REPLACE(["起飞航站代码"], '"', ''),
["降落航站代码"] = REPLACE(["降落航站代码"], '"', '')
SELECT * FROM dbo.T
--更新表T中头字段:将头字段中 双隐号 删除
EXEC sp_rename 'T.["单据编号"]','单据编号'
EXEC sp_rename 'T.["航班计划日期"]','航班计划日期'
EXEC sp_rename 'T.["航班号"]','航班号'
EXEC sp_rename 'T.["起飞航站代码"]','起飞航站代码'
EXEC sp_rename 'T.["降落航站代码"]','降落航站代码'
SELECT * FROM dbo.T
--删除表T中数据
delete from T
SELECT * FROM dbo.T
执行结果:
sqlserver》单击数据库》新建查询(N)》复制SQL语句到空白处》 !执行(X)