Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Interesting Challenge

Author  Topic 

ConradK
Posting Yak Master

140 Posts

Posted - 2010-09-15 : 15:48:34
Okay, so here is the constraints of the challenge.

I have table A and table B.

Every row in table A must become a column in table B.

Table A is this

addme

a
b
c
d

and table B is this:

e,f,g,h
1,1,1,1


I need to update table B to reflect table A in the following way

a,b,c,d,e,f,g,h
null,null,null,null,1,1,1,1

See whats happening here?

I have a list of 'columns' in table A that need to be added in a secondary table, that needs to be turned around and added to table B.



I'm coming up with some ways on my own, but wondering what you may be thinking.

Table A and B are infinitly subject to change, but for certain, the values in table A are not already a part of column B.

Good Luck!

GhantaBro
Posting Yak Master

215 Posts

Posted - 2010-09-15 : 15:55:40
quote:
Originally posted by ConradK

Okay, so here is the constraints of the challenge.

I have table A and table B.

Every row in table A must become a column in table B.

Table A is this

addme

a
b
c
d

and table B is this:

e,f,g,h
1,1,1,1


I need to update table B to reflect table A in the following way

a,b,c,d,e,f,g,h
null,null,null,null,1,1,1,1

See whats happening here?

I have a list of 'columns' in table A that need to be added in a secondary table, that needs to be turned around and added to table B.



I'm coming up with some ways on my own, but wondering what you may be thinking.

Table A and B are infinitly subject to change, but for certain, the values in table A are not already a part of column B.

Good Luck!






You need to put the values in table in a temp table and use dynamic query to create "create table" sql and also "insert into" statements...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-15 : 16:10:18
I would start by creating a normalized data model and would abandon your "concept"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-16 : 04:45:06
yup. This is a crazy model. Even a key value pair model would be better than this. (and that's pretty bad most of the time).

Why don't you tell us what you are actually trying to do and not how you are trying to do it?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -