概念性想法 - 2个表改变其他完整的游标? [英] Conceptual ideas - 2 tables one changes other complete Cursors?

查看:54
本文介绍了概念性想法 - 2个表改变其他完整的游标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为游标可能会帮助我,但我不确定。我正在寻找关于如何解决我遇到的问题的想法




考虑两个表,一个表包含学生信息(非常广泛) />
100字段),学生信息的其他历史变化,

(缩小,只记录变化的字段)。


As示例表一包含STUDENT_ID,STUDENT_MAJOR,STUDENT_NAME,

RECORD_DT并且其中有一名学生。


表二包含STUDENT_ID,STUDENT_MAJOR,CHANGE_DT并包含2

记录,因为学生改变了他们的专业2次。


我想最终得到一个包含3行的表,2对

Major和当前的学生记录。我希望每一行都完整。

我尝试的所有东西(连接,外连接,联合)我最终得到了

某些字段为空(在我的例子中, STUDENT_NAME将在原始行的

中,并且两次更改为null)

我知道这很模糊,但我想知道这是否是一个地方

使用CURSORS?

(你们中的一些人可能认为这是一个类型2维或者慢慢地改变了数据仓库中使用的
更改维度,它是。我需要

建立我的历史变化,我可以把它送到我的仓库。我有

当前的学生记录,以及所有的descreet变化到

的学生。)

TIA

Rob

解决方案

怎么样:


- 代表当前状态

SELECT STUDENT_ID,STUDENT_MAJOR,RECORD_DT,STUDENT_NAME

FROM Table1

UNION ALL

SELECT t2.STUDENT_ ID,t2.STUDENT_MAJOR,t2.CHANGE_DT,t1.STUDENT_NAME

FROM Table2 t2 JOIN Table1 t1 ON t2.STUDENT_ID = t1.STUDENT_ID


或我是遗失了什么?


Stu


怎么样:


- 代表当前状态

SELECT STUDENT_ID,STUDENT_MAJOR,RECORD_DT,STUDENT_NAME

来自表1

UNION ALL

SELECT t2.STUDENT_ID,t2.STUDENT_MAJOR,t2.CHANGE_DT,t1.STUDENT_NAME

FROM Table2 t2 JOIN Table1 t1 ON t2.STUDENT_ID = t1.STUDENT_ID


或者我错过了什么?


Stu




" rcamarda" < RC ****** @ cablespeed.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...

我认为游标可能会帮助我,但我不确定。我正在寻找关于如何解决我遇到的问题的想法。

考虑两个表,一个表包含学生信息(非常宽的100个字段),另一个表学生信息的历史变化,
(缩小,只记录变化的字段)。

作为示例,表一包含STUDENT_ID,STUDENT_MAJOR,STUDENT_NAME,
RECORD_DT并且有一名学生表二包含STUDENT_ID,STUDENT_MAJOR,CHANGE_DT并包含2
记录,因为学生改变了他们的专业2次。

我想结束一个表包含3行,2个更改为主要和当前学生记录。我希望每一行都是完整的。
我尝试的所有东西(连接,外连接,联合)我最终得到了一些字段为空(在我的例子中,STUDENT_NAME将在
原来的行,并且两个更改为null)
我知道这很模糊,但我想知道这是否是一个使用CURSORS的地方?
(你们当中有些人可能会这样做认识到这是一个类型2维度或缓慢地改变数据仓库中使用的维度,它是。我需要建立我的历史更改,我可以将它提供给我的仓库。我有
当前的学生记录,以及对学生所做的所有改变。)
TIA
Rob




你好Rob,


游标是魔鬼脚趾甲。必须有一个联接,可以做你想要的
。你能具体确定你的主键是什么吗?一旦我们有了b $ b,我们就可以继续前进。


问候


SYM。


I think cursors might help me, but I''m not sure. I''m looking for ideas
on how to solve a problem I have.

Consider two tables, one table contains student information (very wide
100 fields) , the other historical changes of the student information,
(narrow, just fields that record changes).

As an example Table one has STUDENT_ID, STUDENT_MAJOR, STUDENT_NAME,
RECORD_DT and has one student in it.

Table two contains STUDENT_ID, STUDENT_MAJOR , CHANGE_DT and contains 2
records, since the student changed their major 2 times.

I want to end up with a table the contains 3 rows, the 2 changes to the
Major and the current student record. I want each row to be complete.
Everything that I have tried (joins, outer joins, union) I end up with
some field being null (in my example, the STUDENT_NAME would on be in
the original row, and null for the two changes)
I know this is pretty vague, but I am wondering if this is a place to
use CURSORS?
(Some of you may recognize this as a type 2 dimension or slowly
changing dimension as used in a data warehouse, which it is. I need to
build up my historical changes to I can feed it to my warehouse. I have
the current student record, and all the descreet changes made to the
student.)
TIA
Rob

解决方案

How about:

--represents current status
SELECT STUDENT_ID, STUDENT_MAJOR, RECORD_DT, STUDENT_NAME
FROM Table1
UNION ALL
SELECT t2.STUDENT_ID, t2.STUDENT_MAJOR, t2.CHANGE_DT, t1.STUDENT_NAME
FROM Table2 t2 JOIN Table1 t1 ON t2.STUDENT_ID = t1.STUDENT_ID

Or am I missing something?

Stu


How about:

--represents current status
SELECT STUDENT_ID, STUDENT_MAJOR, RECORD_DT, STUDENT_NAME
FROM Table1
UNION ALL
SELECT t2.STUDENT_ID, t2.STUDENT_MAJOR, t2.CHANGE_DT, t1.STUDENT_NAME
FROM Table2 t2 JOIN Table1 t1 ON t2.STUDENT_ID = t1.STUDENT_ID

Or am I missing something?

Stu



"rcamarda" <rc******@cablespeed.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

I think cursors might help me, but I''m not sure. I''m looking for ideas
on how to solve a problem I have.

Consider two tables, one table contains student information (very wide
100 fields) , the other historical changes of the student information,
(narrow, just fields that record changes).

As an example Table one has STUDENT_ID, STUDENT_MAJOR, STUDENT_NAME,
RECORD_DT and has one student in it.

Table two contains STUDENT_ID, STUDENT_MAJOR , CHANGE_DT and contains 2
records, since the student changed their major 2 times.

I want to end up with a table the contains 3 rows, the 2 changes to the
Major and the current student record. I want each row to be complete.
Everything that I have tried (joins, outer joins, union) I end up with
some field being null (in my example, the STUDENT_NAME would on be in
the original row, and null for the two changes)
I know this is pretty vague, but I am wondering if this is a place to
use CURSORS?
(Some of you may recognize this as a type 2 dimension or slowly
changing dimension as used in a data warehouse, which it is. I need to
build up my historical changes to I can feed it to my warehouse. I have
the current student record, and all the descreet changes made to the
student.)
TIA
Rob



Hi Rob,

Cursors are the devils toenails. There has to be a join that will do what
you want. Can you identify specifically what your primary key is? Once we
have this we might move forward.

regards

SYM.


这篇关于概念性想法 - 2个表改变其他完整的游标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆