| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 895 人关注过本帖
标题:如何从其他table得到的资料,填写回去现在的table?
只看楼主 加入收藏
musxell
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-12-2
收藏
 问题点数:0 回复次数:1 
如何从其他table得到的资料,填写回去现在的table?
程序代码:
CREATE TABLE #TempFruits
(
       
        [Guid] [uniqueidentifier] NULL,
        [ID] [varchar](512) NULL,
        [Desc] [varchar](512) NULL
)

INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('d001368b-46af-475a-83c3-c8ef40a7de2b', 'USAA', 'UsApple');
INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('35d16568-7ece-4855-a720-19cc96778dc3', 'AFCO', 'AfricaOrange');
INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('0107732a-7438-4f55-a76c-7cadccb47f59', 'THAP', 'ThaiPapaya');

SELECT * FROM #TempFruits

DROP TABLE #TempFruits

---------------------------------------------------------------------------------------------------

CREATE TABLE #TempCountry
(
        [Country] [varchar](512) NULL,       
        [AppleGuid] [uniqueidentifier] NULL,
        [OrangeGuid] [uniqueidentifier] NULL,
        [PapayaGuid] [uniqueidentifier] NULL
)

INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('USA', null, null, null);
INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('AFRICA', null, null, null);
INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('THAI', null, null,null);

SELECT * FROM #TempCountry

DROP TABLE #TempCountry

---------------------------------------------------------------------------------------------------

CREATE TABLE #TempFromExcel
(
        [Country] [varchar](512) NULL,       
        [Apple] [varchar](512) NULL,
        [Orange] [varchar](512) NULL,
        [Papaya] [varchar](512) NULL,
)

INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('USA', 'USAA', null, null);
INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('AFRICA', null, 'AFCO', null);
INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('THAI', null, null, 'THAP');

SELECT * FROM #TempFromExcel

DROP TABLE #TempFromExcel



#TempFruits 和 #TempCountry
这两个是我现在有的table

#TempFromExcel
是我Import资料,来自EXCEL档案

问题来了,现在我有来自EXCEL档案的资料
我该如何从#TempFromExcel join 去 #TempFruits,找出Guid之后
再Update #TempCountry 这个 table呢?

如果做for loop?
一行接一行update

[[it] 本帖最后由 musxell 于 2008-12-2 15:43 编辑 [/it]]
搜索更多相关主题的帖子: table 资料 
2008-12-02 15:42
musxell
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-12-2
收藏
得分:0 
CREATE TABLE #TempFruits
(
      
        [Guid] [uniqueidentifier] NULL,
        [ID] [varchar](512) NULL,
        [Desc] [varchar](512) NULL
)

INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('d001368b-46af-475a-83c3-c8ef40a7de2b', 'USAA', 'UsApple');
INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('35d16568-7ece-4855-a720-19cc96778dc3', 'AFCO', 'AfricaOrange');
INSERT INTO #TempFruits([Guid], [ID], [Desc]) VALUES('0107732a-7438-4f55-a76c-7cadccb47f59', 'THAP', 'ThaiPapaya');

SELECT * FROM #TempFruits



---------------------------------------------------------------------------------------------------

CREATE TABLE #TempCountry
(
        [Country] [varchar](512) NULL,      
        [AppleGuid] [uniqueidentifier] NULL,
        [OrangeGuid] [uniqueidentifier] NULL,
        [PapayaGuid] [uniqueidentifier] NULL
)

INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('USA', null, null, null);
INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('AFRICA', null, null, null);
INSERT INTO #TempCountry([Country], [AppleGuid], [OrangeGuid], [PapayaGuid]) VALUES('THAI', null, null,null);

SELECT * FROM #TempCountry


---------------------------------------------------------------------------------------------------

CREATE TABLE #TempFromExcel
(
        [Country] [varchar](512) NULL,      
        [Apple] [varchar](512) NULL,
        [Orange] [varchar](512) NULL,
        [Papaya] [varchar](512) NULL,
)

INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('USA', 'USAA', null, null);
INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('AFRICA', null, 'AFCO', null);
INSERT INTO #TempFromExcel([Country], [Apple], [Orange], [Papaya]) VALUES('THAI', null, 'AFCO', 'THAP');

SELECT * FROM #TempFromExcel

---------------------------------------------------------------------------------------------------

Select DISTINCT * From (
SELECT E.Country,
            CASE    WHEN F.ID = E.Apple THEN F.Guid END AS AppleGuid,
            CASE WHEN F.ID = E.Orange THEN F.Guid END OrangeGuid,
            CASE WHEN F.ID = E.Papaya THEN F.Guid END AS  PapayaGuid
FROM #TempFruits F INNER JOIN #TempFromExcel E
ON (F.ID = E.Orange OR F.ID = E.Apple OR F.ID = E.Papaya)
) A
Group By Country, AppleGuid, OrangeGuid, PapayaGuid

DROP TABLE #TempFruits
DROP TABLE #TempCountry
DROP TABLE #TempFromExcel


谁能帮我看看呢?
execute上面的SQL
出现了两个THAI,我要GROUP它们成一笔
如何呢?
出来的答案是
THAI只有一笔,guid自动和拼
2008-12-03 22:30
快速回复:如何从其他table得到的资料,填写回去现在的table?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026033 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved