Home All Groups Group Topic Archive Search About
Author
14 Sep 2006 7:28 PM
Anonymous
I have 2 tables in SQL Server 2000.

Table1:
ID           Field1      Field2       Field3
111


Table2:
ID         Field         Code
111       blue          1
111       red           2
111       yellow       3

I need to update Field1, Field2, and Field3 in table1 as follows joining on
the ID:

If Table2.Code = 1 update Table1.Field1
If Table2.Code = 2 update Table1.Field2
If Table3.Code = 3 update Table1.Field3

Final Results will be

Table1:
ID           Field1      Field2       Field3
111         blue        red           yellow

Author
14 Sep 2006 7:48 PM
Mark
What is the rule here?
Does the code column always contain 1, 2, or 3?

Please provide the real table names, data and the exact rule. Otherwise, we
DBA will be wasting our time in guessing and providing solutions for nothing.

-Nitin Rana

Show quote
"Anonymous" wrote:

> I have 2 tables in SQL Server 2000.
>
> Table1:
> ID           Field1      Field2       Field3
> 111
>
>
> Table2:
> ID         Field         Code
> 111       blue          1
> 111       red           2
> 111       yellow       3
>
> I need to update Field1, Field2, and Field3 in table1 as follows joining on
> the ID:
>
> If Table2.Code = 1 update Table1.Field1
> If Table2.Code = 2 update Table1.Field2
> If Table3.Code = 3 update Table1.Field3
>
> Final Results will be
>
> Table1:
> ID           Field1      Field2       Field3
> 111         blue        red           yellow
>
>
>
>
>
Author
14 Sep 2006 8:56 PM
Anonymous
No, the code column will not always contain 1, 2, 3.

Here are the exact names of the tables and fields.

tblCombined
CombinedID         sf1date          sf2date         sf3date        sf4date  
    sf5date
111
222
333

tblCombinedDate
CombinedID         sfdate               code
111                     1/1/06                1
111                     2/3/06                2
111                     4/15/06               3
111                     10/11/06             4
111                     6/21/06               5
222                     12/15/05             1

After the update. tblCombined will have the following data:

tblCombined
CombinedID         sf1date          sf2date         sf3date        sf4date  
    sf5date
111                     1/1/06           2/3/6            4/15/06      
10/11/06     6/21/06
222                     12/15/05
333

Anything with a code 1 will update sf1date, code 2 will update sf2date, etc.

A record in tblCombinedDate will not have a code 2 or 3 without a 1.  In
other words, the code values for a given CombinedID all start at 1 and
increment by 1 and are unique for a given CombinedID.  You will not see

CombinedID               Code
111                           1
111                           2
111                           1

Not all records in tblCombined will have records in tblCombinedDate.  Not
all records in tblCombinedDate will have 5 codes.  In the example, CombinedID
of 222 only as 1 record in tblCombinedDate.


Show quote
"Mark" wrote:

> What is the rule here?
> Does the code column always contain 1, 2, or 3?
>
> Please provide the real table names, data and the exact rule. Otherwise, we
> DBA will be wasting our time in guessing and providing solutions for nothing.
>
> -Nitin Rana
>
> "Anonymous" wrote:
>
> > I have 2 tables in SQL Server 2000.
> >
> > Table1:
> > ID           Field1      Field2       Field3
> > 111
> >
> >
> > Table2:
> > ID         Field         Code
> > 111       blue          1
> > 111       red           2
> > 111       yellow       3
> >
> > I need to update Field1, Field2, and Field3 in table1 as follows joining on
> > the ID:
> >
> > If Table2.Code = 1 update Table1.Field1
> > If Table2.Code = 2 update Table1.Field2
> > If Table3.Code = 3 update Table1.Field3
> >
> > Final Results will be
> >
> > Table1:
> > ID           Field1      Field2       Field3
> > 111         blue        red           yellow
> >
> >
> >
> >
> >
Author
14 Sep 2006 10:31 PM
Anith Sen
There are several problems with your requirement, mostly arising from poor
design. Why do you want to have redundant data in two tables? Assuming
significance to positions is a bad way to design database systems. Also
having ordinal positions of columns in one table represented as values in a
column in another table a bad design scheme as well.

What exactly is your business problem? What is the requirement that force
you to insert and manage data in both tables? If this is a reporting
requirement, have you considered derived this data rather than managing them
within the database?

--
Anith
Author
15 Sep 2006 2:18 PM
Anonymous
I appreciate everyone all this forum who answers the questions posted.  I
also understand why some feel they need to question everythng . . . I know
you only want to make sure that people are following the normalization rules.

Often times though I just wish if you want to provide feedback . . . great
but could you also answer the questions posted and not always assume the
person who asked the question doesn't have a clue.

This is not a database where the data is being updated.  I was given 40,000
records to combine via a single spreadsheet.  I imported the data to a SQL
table and am trying to clean it up.  It is not my data, thus not my design. 
In a perfect world you would be given the data in a way that completely makes
sense but I am at the mercy of the client and have to make it work with what
I am given.

Once the data is combined per the client's business rules we will have to QA
the data which is why I am trying to break it out in logical pieces that are
easy to check and verify against.

So if anyone knows how to answer my original question, I would appreciate it.

Show quote
"Anonymous" wrote:

> I have 2 tables in SQL Server 2000.
>
> Table1:
> ID           Field1      Field2       Field3
> 111
>
>
> Table2:
> ID         Field         Code
> 111       blue          1
> 111       red           2
> 111       yellow       3
>
> I need to update Field1, Field2, and Field3 in table1 as follows joining on
> the ID:
>
> If Table2.Code = 1 update Table1.Field1
> If Table2.Code = 2 update Table1.Field2
> If Table3.Code = 3 update Table1.Field3
>
> Final Results will be
>
> Table1:
> ID           Field1      Field2       Field3
> 111         blue        red           yellow
>
>
>
>
>
Author
15 Sep 2006 2:41 PM
Jim Underwood
I think Joe Celko put it best with the example of a woodworkers group where
someone asks what is the best rock to use to hammer a screw into oak.  One
can reccomend using a round marble rock, or point out that a screwdriver
would be a better approach.  80 percent of the time folks come here looking
for specific code to accomodate a specific approach, when a different design
or approach will serve them much better.  It is not a matter of questioning
everything, as much as trying to provide the best solution (and sometimes
education) for the poster.  Sometimes it is simply a matter of making sure
anyone else who is reading the newsgroup understands that this is not the
proper way to do it, even if it is appropriate for the particular post in
question.

It would be irresponsible to post a solution without explaining the other
problems that would arrise from the approach.  This is, after all, as much
an intellectual forum as it is a technical help forum.

To answer your question, however...

You can do this with multiple joins or with case statements and aggregates.

You can use case to get everything in the right columns, but still in
multiple rows.

select CombinedID
, case when code=1 then sfdate end as sf1date
, case when code=2 then sfdate end as sf2date
, case when code=3 then sfdate end as sf3date
, case when code=4 then sfdate end as sf4date
, case when code=5 then sfdate end as sf5date
from tblCombinedDate

Then take the max of each column grouped by CombinedID to get one row
instead of 5.

select CombinedID
, max(case when code=1 then sfdate end) as sf1date
, max(case when code=2 then sfdate end) as sf2date
, max(case when code=3 then sfdate end) as sf3date
, max(case when code=4 then sfdate end) as sf4date
, max(case when code=5 then sfdate end) as sf5date
from tblCombinedDate

With the multiple joins, you would use:

Select a.CombinedID
, a.sfdate as sf1date
, b.sfdate as sf2date
, c.sfdate as sf3date
, d.sfdate as sf4date
, e.sfdate as sf5date
from tblCombinedDate as a
inner join tblCombinedDate as b
  on a.CombinedID = b.CombinedID
  and b.code = 2
inner join tblCombinedDate as c
  on a.CombinedID = c.CombinedID
  and c.code = 3
inner join tblCombinedDate as d
  on a.CombinedID = d.CombinedID
  and d.code = 4
inner join tblCombinedDate as e
  on a.CombinedID = e.CombinedID
  and e.code = 5
where a.code=1

If you did not always have all 5 values, you would use outer joins instead
of inner joins.

Show quote
"Anonymous" <Anonym***@discussions.microsoft.com> wrote in message
news:19BA28B9-B8A3-4E81-A7E9-CB00BFD66116@microsoft.com...
> I appreciate everyone all this forum who answers the questions posted.  I
> also understand why some feel they need to question everythng . . . I know
> you only want to make sure that people are following the normalization
rules.
>
> Often times though I just wish if you want to provide feedback . . . great
> but could you also answer the questions posted and not always assume the
> person who asked the question doesn't have a clue.
>
> This is not a database where the data is being updated.  I was given
40,000
> records to combine via a single spreadsheet.  I imported the data to a SQL
> table and am trying to clean it up.  It is not my data, thus not my
design.
> In a perfect world you would be given the data in a way that completely
makes
> sense but I am at the mercy of the client and have to make it work with
what
> I am given.
>
> Once the data is combined per the client's business rules we will have to
QA
> the data which is why I am trying to break it out in logical pieces that
are
> easy to check and verify against.
>
> So if anyone knows how to answer my original question, I would appreciate
it.
>
> "Anonymous" wrote:
>
> > I have 2 tables in SQL Server 2000.
> >
> > Table1:
> > ID           Field1      Field2       Field3
> > 111
> >
> >
> > Table2:
> > ID         Field         Code
> > 111       blue          1
> > 111       red           2
> > 111       yellow       3
> >
> > I need to update Field1, Field2, and Field3 in table1 as follows joining
on
> > the ID:
> >
> > If Table2.Code = 1 update Table1.Field1
> > If Table2.Code = 2 update Table1.Field2
> > If Table3.Code = 3 update Table1.Field3
> >
> > Final Results will be
> >
> > Table1:
> > ID           Field1      Field2       Field3
> > 111         blue        red           yellow
> >
> >
> >
> >
> >
Author
15 Sep 2006 2:49 PM
Jim Underwood
I should have added...

Since you need to get this into a spreadsheet, you may not need the table at
all the the queries in my last post may get you what you need.  However, you
can use those result sets to insert into your combined table, or to retrieve
the values for updating it.

You can also do something like this to do a direct update.

Update tblCombined
set sf1date =
(
select sfdate from tblCombinedDate as a
where a.CombinedID = tblCombined.CombinedID
and a.code = 1
)
set sf2date =
(
select sfdate from tblCombinedDate as a
where a.CombinedID = tblCombined.CombinedID
and a.code = 2
)
set sf3date =
(
select sfdate from tblCombinedDate as a
where a.CombinedID = tblCombined.CombinedID
and a.code = 3
)
set sf4date =
(
select sfdate from tblCombinedDate as a
where a.CombinedID = tblCombined.CombinedID
and a.code = 4
)
set sf5date =
(
select sfdate from tblCombinedDate as a
where a.CombinedID = tblCombined.CombinedID
and a.code = 5
)

Show quote
"Jim Underwood" <james.underwoodATfallonclinic.com> wrote in message
news:u8SQNUN2GHA.4476@TK2MSFTNGP02.phx.gbl...
> I think Joe Celko put it best with the example of a woodworkers group
where
> someone asks what is the best rock to use to hammer a screw into oak.  One
> can reccomend using a round marble rock, or point out that a screwdriver
> would be a better approach.  80 percent of the time folks come here
looking
> for specific code to accomodate a specific approach, when a different
design
> or approach will serve them much better.  It is not a matter of
questioning
> everything, as much as trying to provide the best solution (and sometimes
> education) for the poster.  Sometimes it is simply a matter of making sure
> anyone else who is reading the newsgroup understands that this is not the
> proper way to do it, even if it is appropriate for the particular post in
> question.
>
> It would be irresponsible to post a solution without explaining the other
> problems that would arrise from the approach.  This is, after all, as much
> an intellectual forum as it is a technical help forum.
>
> To answer your question, however...
>
> You can do this with multiple joins or with case statements and
aggregates.
>
> You can use case to get everything in the right columns, but still in
> multiple rows.
>
> select CombinedID
> , case when code=1 then sfdate end as sf1date
> , case when code=2 then sfdate end as sf2date
> , case when code=3 then sfdate end as sf3date
> , case when code=4 then sfdate end as sf4date
> , case when code=5 then sfdate end as sf5date
> from tblCombinedDate
>
> Then take the max of each column grouped by CombinedID to get one row
> instead of 5.
>
> select CombinedID
> , max(case when code=1 then sfdate end) as sf1date
> , max(case when code=2 then sfdate end) as sf2date
> , max(case when code=3 then sfdate end) as sf3date
> , max(case when code=4 then sfdate end) as sf4date
> , max(case when code=5 then sfdate end) as sf5date
> from tblCombinedDate
>
> With the multiple joins, you would use:
>
> Select a.CombinedID
> , a.sfdate as sf1date
> , b.sfdate as sf2date
> , c.sfdate as sf3date
> , d.sfdate as sf4date
> , e.sfdate as sf5date
> from tblCombinedDate as a
> inner join tblCombinedDate as b
>   on a.CombinedID = b.CombinedID
>   and b.code = 2
> inner join tblCombinedDate as c
>   on a.CombinedID = c.CombinedID
>   and c.code = 3
> inner join tblCombinedDate as d
>   on a.CombinedID = d.CombinedID
>   and d.code = 4
> inner join tblCombinedDate as e
>   on a.CombinedID = e.CombinedID
>   and e.code = 5
> where a.code=1
>
> If you did not always have all 5 values, you would use outer joins instead
> of inner joins.
>
> "Anonymous" <Anonym***@discussions.microsoft.com> wrote in message
> news:19BA28B9-B8A3-4E81-A7E9-CB00BFD66116@microsoft.com...
> > I appreciate everyone all this forum who answers the questions posted.
I
> > also understand why some feel they need to question everythng . . . I
know
> > you only want to make sure that people are following the normalization
> rules.
> >
> > Often times though I just wish if you want to provide feedback . . .
great
> > but could you also answer the questions posted and not always assume the
> > person who asked the question doesn't have a clue.
> >
> > This is not a database where the data is being updated.  I was given
> 40,000
> > records to combine via a single spreadsheet.  I imported the data to a
SQL
> > table and am trying to clean it up.  It is not my data, thus not my
> design.
> > In a perfect world you would be given the data in a way that completely
> makes
> > sense but I am at the mercy of the client and have to make it work with
> what
> > I am given.
> >
> > Once the data is combined per the client's business rules we will have
to
> QA
> > the data which is why I am trying to break it out in logical pieces that
> are
> > easy to check and verify against.
> >
> > So if anyone knows how to answer my original question, I would
appreciate
> it.
> >
> > "Anonymous" wrote:
> >
> > > I have 2 tables in SQL Server 2000.
> > >
> > > Table1:
> > > ID           Field1      Field2       Field3
> > > 111
> > >
> > >
> > > Table2:
> > > ID         Field         Code
> > > 111       blue          1
> > > 111       red           2
> > > 111       yellow       3
> > >
> > > I need to update Field1, Field2, and Field3 in table1 as follows
joining
> on
> > > the ID:
> > >
> > > If Table2.Code = 1 update Table1.Field1
> > > If Table2.Code = 2 update Table1.Field2
> > > If Table3.Code = 3 update Table1.Field3
> > >
> > > Final Results will be
> > >
> > > Table1:
> > > ID           Field1      Field2       Field3
> > > 111         blue        red           yellow
> > >
> > >
> > >
> > >
> > >
>
>
Author
15 Sep 2006 3:29 PM
Anonymous
Jim, thank you for your reply . . . I do appreciate the help.  I also agree
with your first statement and that is kind of what I was trying to say
through my frustration is that people should question the methods but at the
same time respond to the actual question.

Again thanks for the help!

Show quote
"Jim Underwood" wrote:

> I should have added...
>
> Since you need to get this into a spreadsheet, you may not need the table at
> all the the queries in my last post may get you what you need.  However, you
> can use those result sets to insert into your combined table, or to retrieve
> the values for updating it.
>
> You can also do something like this to do a direct update.
>
> Update tblCombined
> set sf1date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 1
> )
> set sf2date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 2
> )
> set sf3date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 3
> )
> set sf4date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 4
> )
> set sf5date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 5
> )
>
> "Jim Underwood" <james.underwoodATfallonclinic.com> wrote in message
> news:u8SQNUN2GHA.4476@TK2MSFTNGP02.phx.gbl...
> > I think Joe Celko put it best with the example of a woodworkers group
> where
> > someone asks what is the best rock to use to hammer a screw into oak.  One
> > can reccomend using a round marble rock, or point out that a screwdriver
> > would be a better approach.  80 percent of the time folks come here
> looking
> > for specific code to accomodate a specific approach, when a different
> design
> > or approach will serve them much better.  It is not a matter of
> questioning
> > everything, as much as trying to provide the best solution (and sometimes
> > education) for the poster.  Sometimes it is simply a matter of making sure
> > anyone else who is reading the newsgroup understands that this is not the
> > proper way to do it, even if it is appropriate for the particular post in
> > question.
> >
> > It would be irresponsible to post a solution without explaining the other
> > problems that would arrise from the approach.  This is, after all, as much
> > an intellectual forum as it is a technical help forum.
> >
> > To answer your question, however...
> >
> > You can do this with multiple joins or with case statements and
> aggregates.
> >
> > You can use case to get everything in the right columns, but still in
> > multiple rows.
> >
> > select CombinedID
> > , case when code=1 then sfdate end as sf1date
> > , case when code=2 then sfdate end as sf2date
> > , case when code=3 then sfdate end as sf3date
> > , case when code=4 then sfdate end as sf4date
> > , case when code=5 then sfdate end as sf5date
> > from tblCombinedDate
> >
> > Then take the max of each column grouped by CombinedID to get one row
> > instead of 5.
> >
> > select CombinedID
> > , max(case when code=1 then sfdate end) as sf1date
> > , max(case when code=2 then sfdate end) as sf2date
> > , max(case when code=3 then sfdate end) as sf3date
> > , max(case when code=4 then sfdate end) as sf4date
> > , max(case when code=5 then sfdate end) as sf5date
> > from tblCombinedDate
> >
> > With the multiple joins, you would use:
> >
> > Select a.CombinedID
> > , a.sfdate as sf1date
> > , b.sfdate as sf2date
> > , c.sfdate as sf3date
> > , d.sfdate as sf4date
> > , e.sfdate as sf5date
> > from tblCombinedDate as a
> > inner join tblCombinedDate as b
> >   on a.CombinedID = b.CombinedID
> >   and b.code = 2
> > inner join tblCombinedDate as c
> >   on a.CombinedID = c.CombinedID
> >   and c.code = 3
> > inner join tblCombinedDate as d
> >   on a.CombinedID = d.CombinedID
> >   and d.code = 4
> > inner join tblCombinedDate as e
> >   on a.CombinedID = e.CombinedID
> >   and e.code = 5
> > where a.code=1
> >
> > If you did not always have all 5 values, you would use outer joins instead
> > of inner joins.
> >
> > "Anonymous" <Anonym***@discussions.microsoft.com> wrote in message
> > news:19BA28B9-B8A3-4E81-A7E9-CB00BFD66116@microsoft.com...
> > > I appreciate everyone all this forum who answers the questions posted.
> I
> > > also understand why some feel they need to question everythng . . . I
> know
> > > you only want to make sure that people are following the normalization
> > rules.
> > >
> > > Often times though I just wish if you want to provide feedback . . .
> great
> > > but could you also answer the questions posted and not always assume the
> > > person who asked the question doesn't have a clue.
> > >
> > > This is not a database where the data is being updated.  I was given
> > 40,000
> > > records to combine via a single spreadsheet.  I imported the data to a
> SQL
> > > table and am trying to clean it up.  It is not my data, thus not my
> > design.
> > > In a perfect world you would be given the data in a way that completely
> > makes
> > > sense but I am at the mercy of the client and have to make it work with
> > what
> > > I am given.
> > >
> > > Once the data is combined per the client's business rules we will have
> to
> > QA
> > > the data which is why I am trying to break it out in logical pieces that
> > are
> > > easy to check and verify against.
> > >
> > > So if anyone knows how to answer my original question, I would
> appreciate
> > it.
> > >
> > > "Anonymous" wrote:
> > >
> > > > I have 2 tables in SQL Server 2000.
> > > >
> > > > Table1:
> > > > ID           Field1      Field2       Field3
> > > > 111
> > > >
> > > >
> > > > Table2:
> > > > ID         Field         Code
> > > > 111       blue          1
> > > > 111       red           2
> > > > 111       yellow       3
> > > >
> > > > I need to update Field1, Field2, and Field3 in table1 as follows
> joining
> > on
> > > > the ID:
> > > >
> > > > If Table2.Code = 1 update Table1.Field1
> > > > If Table2.Code = 2 update Table1.Field2
> > > > If Table3.Code = 3 update Table1.Field3
> > > >
> > > > Final Results will be
> > > >
> > > > Table1:
> > > > ID           Field1      Field2       Field3
> > > > 111         blue        red           yellow
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
>
>
>
Author
15 Sep 2006 3:51 PM
Anonymous
The update statement worked perfectly!

Show quote
"Jim Underwood" wrote:

> I should have added...
>
> Since you need to get this into a spreadsheet, you may not need the table at
> all the the queries in my last post may get you what you need.  However, you
> can use those result sets to insert into your combined table, or to retrieve
> the values for updating it.
>
> You can also do something like this to do a direct update.
>
> Update tblCombined
> set sf1date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 1
> )
> set sf2date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 2
> )
> set sf3date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 3
> )
> set sf4date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 4
> )
> set sf5date =
> (
> select sfdate from tblCombinedDate as a
> where a.CombinedID = tblCombined.CombinedID
> and a.code = 5
> )
>
> "Jim Underwood" <james.underwoodATfallonclinic.com> wrote in message
> news:u8SQNUN2GHA.4476@TK2MSFTNGP02.phx.gbl...
> > I think Joe Celko put it best with the example of a woodworkers group
> where
> > someone asks what is the best rock to use to hammer a screw into oak.  One
> > can reccomend using a round marble rock, or point out that a screwdriver
> > would be a better approach.  80 percent of the time folks come here
> looking
> > for specific code to accomodate a specific approach, when a different
> design
> > or approach will serve them much better.  It is not a matter of
> questioning
> > everything, as much as trying to provide the best solution (and sometimes
> > education) for the poster.  Sometimes it is simply a matter of making sure
> > anyone else who is reading the newsgroup understands that this is not the
> > proper way to do it, even if it is appropriate for the particular post in
> > question.
> >
> > It would be irresponsible to post a solution without explaining the other
> > problems that would arrise from the approach.  This is, after all, as much
> > an intellectual forum as it is a technical help forum.
> >
> > To answer your question, however...
> >
> > You can do this with multiple joins or with case statements and
> aggregates.
> >
> > You can use case to get everything in the right columns, but still in
> > multiple rows.
> >
> > select CombinedID
> > , case when code=1 then sfdate end as sf1date
> > , case when code=2 then sfdate end as sf2date
> > , case when code=3 then sfdate end as sf3date
> > , case when code=4 then sfdate end as sf4date
> > , case when code=5 then sfdate end as sf5date
> > from tblCombinedDate
> >
> > Then take the max of each column grouped by CombinedID to get one row
> > instead of 5.
> >
> > select CombinedID
> > , max(case when code=1 then sfdate end) as sf1date
> > , max(case when code=2 then sfdate end) as sf2date
> > , max(case when code=3 then sfdate end) as sf3date
> > , max(case when code=4 then sfdate end) as sf4date
> > , max(case when code=5 then sfdate end) as sf5date
> > from tblCombinedDate
> >
> > With the multiple joins, you would use:
> >
> > Select a.CombinedID
> > , a.sfdate as sf1date
> > , b.sfdate as sf2date
> > , c.sfdate as sf3date
> > , d.sfdate as sf4date
> > , e.sfdate as sf5date
> > from tblCombinedDate as a
> > inner join tblCombinedDate as b
> >   on a.CombinedID = b.CombinedID
> >   and b.code = 2
> > inner join tblCombinedDate as c
> >   on a.CombinedID = c.CombinedID
> >   and c.code = 3
> > inner join tblCombinedDate as d
> >   on a.CombinedID = d.CombinedID
> >   and d.code = 4
> > inner join tblCombinedDate as e
> >   on a.CombinedID = e.CombinedID
> >   and e.code = 5
> > where a.code=1
> >
> > If you did not always have all 5 values, you would use outer joins instead
> > of inner joins.
> >
> > "Anonymous" <Anonym***@discussions.microsoft.com> wrote in message
> > news:19BA28B9-B8A3-4E81-A7E9-CB00BFD66116@microsoft.com...
> > > I appreciate everyone all this forum who answers the questions posted.
> I
> > > also understand why some feel they need to question everythng . . . I
> know
> > > you only want to make sure that people are following the normalization
> > rules.
> > >
> > > Often times though I just wish if you want to provide feedback . . .
> great
> > > but could you also answer the questions posted and not always assume the
> > > person who asked the question doesn't have a clue.
> > >
> > > This is not a database where the data is being updated.  I was given
> > 40,000
> > > records to combine via a single spreadsheet.  I imported the data to a
> SQL
> > > table and am trying to clean it up.  It is not my data, thus not my
> > design.
> > > In a perfect world you would be given the data in a way that completely
> > makes
> > > sense but I am at the mercy of the client and have to make it work with
> > what
> > > I am given.
> > >
> > > Once the data is combined per the client's business rules we will have
> to
> > QA
> > > the data which is why I am trying to break it out in logical pieces that
> > are
> > > easy to check and verify against.
> > >
> > > So if anyone knows how to answer my original question, I would
> appreciate
> > it.
> > >
> > > "Anonymous" wrote:
> > >
> > > > I have 2 tables in SQL Server 2000.
> > > >
> > > > Table1:
> > > > ID           Field1      Field2       Field3
> > > > 111
> > > >
> > > >
> > > > Table2:
> > > > ID         Field         Code
> > > > 111       blue          1
> > > > 111       red           2
> > > > 111       yellow       3
> > > >
> > > > I need to update Field1, Field2, and Field3 in table1 as follows
> joining
> > on
> > > > the ID:
> > > >
> > > > If Table2.Code = 1 update Table1.Field1
> > > > If Table2.Code = 2 update Table1.Field2
> > > > If Table3.Code = 3 update Table1.Field3
> > > >
> > > > Final Results will be
> > > >
> > > > Table1:
> > > > ID           Field1      Field2       Field3
> > > > 111         blue        red           yellow
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
>
>
>

AddThis Social Bookmark Button