sql 复制表问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:19:38
有两张表 分别是t1,t3,
t1的表结构为:
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[posttime] [datetime] NULL DEFAULT (getdate()),
[classID] [int] NULL,

t2的表结构为:
[id] [int] IDENTITY(1,1) NOT NULL,
[name1] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[content1] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[posttime1] [datetime] NULL DEFAULT (getdate()),
[classname] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,

t3的表内容有:
id name1 content1 posttime1 classname
1 第一个 第一个 2009-8-9 国际新闻
2 第二个 第二个 2009-8-9 国内新闻
3 第三个 第三个 2009-8-9 娱乐新闻

现在从从t3表的内容复制到t1 要求当t3 classname为国际新闻 t1的classid为1 为国内新闻时classid 为2 为娱乐新闻时 classid为3

insert into t1 (name,content,posttime,classid)
select name1, content1, posttime1 ,case classname when '国际新闻' then 1 when '国内新闻' then 2 when '娱乐新闻' then 3 end case from t3

insert into t1(name,content,posttime,classID)
select
name1,content1,posttime1,
(case
when classname='国际新闻' then 1
when classname='国内新闻' then 2
else 3) as classid
from t3

不行hi我,或者问题补充一下

insert into t1(name,content,posttime,classID)
select
name1,content1,posttime1,
(case classname
when '国际新闻' then 1
when '国内新闻' then 2
else 3 end) as classid
from t3