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 Administration
 Join between 2 tables

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-09 : 14:03:15
Hi
I have a tricky situation here as Iam new to SQL administration and need advise on how to proceed

I have a table(Table A) in prod environment with 22 columns to store customer identification numbers.this table has limitations because it can only save 15 customer numbers

we designed a new table(table B) in testing environment which will save the customer identification numbers in rows and not columns to eliminate limitations and save as many customer identification numbers as we want

all our downstream process are connected to the Table A for the information saved on it

how do we transition to use the new table and integrate the new table to the production environment so that it does not affect anything that is running currently

Need Help,Ideas and plans

Thanks
Vamsi


X002548
Not Just a Number

15586 Posts

Posted - 2010-08-09 : 14:28:07
a View should do it

Please post the DDL of the tables, and some sample DML data examples to insert into thos tables



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

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-09 : 15:06:14
Table A-Saves the customer policy numbers based on platform.for example platform A customers policy numbers get saved to relevant policy feilds for platorm A and so on.
RequestId
Platform A
platform B
platform C
platform D
PolicynoA1
PolicynoA2
PolicynoA3
PolicynoA4
PolicynoA5
PolicynoB1
PolicynoB2
PolicynoB3
PolicynoB4
PolicynoB5
PolicynoC1
PolicynoC2
PolicynoC3
PolicynoC4
PolicynoC5
PolicynoD1
PolicynoD2
PolicynoD3
PolicynoD4
PolicynoD5

The Above table A is not scalable as it cannot save more than 5 policies per platofrm we though this would be useless going forward and designed Table B

Table B
RequestId
Policy
platform

This way we can save any number of policies with each request

How do you think a view will solve the purpose

thanks


Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2010-08-09 : 17:57:31
quote:
Originally posted by X002548

a View should do it

Please post the DDL of the tables, and some sample DML data examples to insert into thos tables
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


Why would you want to use a view on a production database? This could create a performance hit due to IO usage. At my company we only use views for querying against a reporting server..

The original post seems to suggest that you want to remap data from A to B and then use B in production. Couldn't this be accomplished by simply copying data from A to B? I can think of a couple of ways to do this..

R&R

Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-09 : 22:58:55
can you please advise how this can be accomplished by remaping the data from A to B
Iam thinking of some logic but not sure how to proceed by remaping data from A to B

Please advise
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-08-10 : 00:46:36
what is the version of SQL Server you are using ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lusiya
Starting Member

1 Post

Posted - 2010-08-10 : 03:24:53
An interactive discussion forum and community gathering place for ... SUBMIT ARTICLE · Submit Article. Contact Info · Contact Us · Link to Us · Recommend ...

_______________________________________________________________________--Want to get-on Google's first page and loads of traffic to your website? Hire a SEO Specialist from Ocean Groups [url=http://oceangroups.org/]seo pecialist [/url]


L
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-10 : 10:52:53
we are on sqlserver 2005

Iam using the 2008 version of managemnet studio
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2010-08-10 : 11:16:30
Can you post the output of a query from Table A? Maybe 10 or so records?



r&r
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 11:32:38
quote:
Originally posted by revdnrdy

[quote]Originally posted by X002548
Why would you want to use a view on a production database? This could create a performance hit due to IO usage. At my company we only use views for querying against a reporting server..



What company is that?

Performance hit due to IO Usage???

Do yoy know what you're talkin about?

Or are you just parroting what some mucky muck told you?



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

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 11:37:12
quote:
Originally posted by jim_jim

can you please advise how this can be accomplished by remaping the data from A to B
Iam thinking of some logic but not sure how to proceed by remaping data from A to B

Please advise



Well....I sugegsted a view so you wouldn't affect down stream programs...that would still limit you to the original structure of Table A....

However any new code or programs could take advantage of the new table b without limitations

In other words...all OLD code MUST be stuck with limitations if you're plan is to not rewrite them

All NEW code would have the restraints removed.

In effect, you have normalized your database structure

GOOD FOR YOU...

Hold on and I'll post and example...



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

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 11:44:57
Real Table DDL would be helpful here...

do you know how to script it out of SSMS?



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

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-10 : 11:47:42
How do i post?Iam not sure whether there is a way to attach some sample stuff
Below is the sample data

The Sample Data says requestno:133,Platform A is selected and 5 numbers are associated with the request




Requestid Platform A Platform B Platform C Platform D Polcyno A1 Polcyno A2 Polcyno A3 Polcyno A4 Polcyno A5
133 Yes NULL NULL NULL 98781 98782 98783 98784 98785
134 NULL Yes NULL NULL NULL NULL NULL NULL NULL
135 NULL NULL Yes NULL NULL NULL NULL NULL NULL
136 NULL NULL NULL Yes NULL NULL NULL NULL NULL
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2010-08-10 : 11:56:08
Well.. you can run a query then copy the results to this forum.
Make sure you wrap code tags around anything you post. Notice I took your table and put code tags around it so it displays nicely.

If you do post output from a query you only need to post about 10 lines or so.. don't post 1000 rows (thats just spamming)..


Rid PlatA PlatB PlatC PlatD Policy A1 Policyno A2
133 Yes NULL NULL NULL 98781 98782 98783 98784
134 NULL Yes NULL NULL NULL NULL NULL NULL
135 NULL NULL Yes NULL NULL NULL NULL NULL
136 NULL NULL NULL Yes NULL NULL NULL NULL



r&r
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2010-08-10 : 12:10:02
quote:

Do yoy know what you're talkin about?
Or are you just parroting what some mucky muck told you?




Thats funny cause when I read your post I thought the same thing..
Do you always respond as a 10 yr old child when someone disagrees with you?
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-10 : 12:17:49
Can you suggest what we can do looking at the sample data posted
I Ran a query,pasted to excel did some modifications and posted it

Thanks
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 13:08:43
well, the sample data would have been helpful awhile ago...

In any case..the decision on direction is going to be dependant upong the impact of the ultimate changes, and what you plan to do..

If there are only a handful of programs, then you should bite the bullet and make the change to normalized data

anyway...here is a hack that uses the view


CREATE TABLE myTableA99 (
RequestID int IDENTITY(1,1)
, [Platform A] varchar(50)
, [Platform B] varchar(50)
, [Platform C] varchar(50)
, [Platform D] varchar(50)
, PolicynoA1 varchar(50)
, PolicynoA2 varchar(50)
, PolicynoA3 varchar(50)
, PolicynoA4 varchar(50)
, PolicynoA5 varchar(50)
, PolicynoB1 varchar(50)
, PolicynoB2 varchar(50)
, PolicynoB3 varchar(50)
, PolicynoB4 varchar(50)
, PolicynoB5 varchar(50)
, PolicynoC1 varchar(50)
, PolicynoC2 varchar(50)
, PolicynoC3 varchar(50)
, PolicynoC4 varchar(50)
, PolicynoC5 varchar(50)
, PolicynoD1 varchar(50)
, PolicynoD2 varchar(50)
, PolicynoD3 varchar(50)
, PolicynoD4 varchar(50)
, PolicynoD5 varchar(50)
)
GO

CREATE TABLE myTableB99 (
[RequestID] int
, [RequestSubID] int IDENTITY(1,1)
, [Platform] varchar(50)
, [Policy] varchar(50)
, [xGrid] char(1)
, [yGrid] char(1)
)
GO

INSERT INTO myTableA99(
-- RequestID int IDENTITY(1,1)
[Platform A]
, [Platform B]
, [Platform C]
, [Platform D]
, PolicynoA1
, PolicynoA2
, PolicynoA3
, PolicynoA4
, PolicynoA5
, PolicynoB1
, PolicynoB2
, PolicynoB3
, PolicynoB4
, PolicynoB5
, PolicynoC1
, PolicynoC2
, PolicynoC3
, PolicynoC4
, PolicynoC5
, PolicynoD1
, PolicynoD2
, PolicynoD3
, PolicynoD4
, PolicynoD5
)
SELECT 'A1', 'B1', 'C1', 'D1'
, 'PolicynoA1A', 'PolicynoA2A', 'PolicynoA3A', 'PolicynoA4A', 'PolicynoA5A'
, 'PolicynoB1B', 'PolicynoB2B', 'PolicynoB3B', 'PolicynoB4B', 'PolicynoB5B'
, 'PolicynoC1C', 'PolicynoC2C', 'PolicynoC3C', 'PolicynoC4C', 'PolicynoC5C'
, 'PolicynoD1D', 'PolicynoD2D', 'PolicynoD3D', 'PolicynoD4D', 'PolicynoD5D'
UNION ALL
SELECT 'A2', 'B2', 'C2', 'D2'
, 'PolicynoA1W', 'PolicynoA2W', 'PolicynoA3W', 'PolicynoA4W', 'PolicynoA5W'
, 'PolicynoB1X', 'PolicynoB2X', 'PolicynoB3X', 'PolicynoB4X', 'PolicynoB5X'
, 'PolicynoC1Y', 'PolicynoC2Y', 'PolicynoC3Y', 'PolicynoC4Y', 'PolicynoC5Y'
, 'PolicynoD1Z', 'PolicynoD2Z', 'PolicynoD3Z', 'PolicynoD4Z', 'PolicynoD5Z'
GO


-- Noramalize Data

INSERT INTO myTableB99 (
[RequestID]
-- , [RequestSubID]
, [Platform]
, [Policy]
, [xGrid]
, [yGrid]
)
SELECT RequestID, [Platform A], PolicynoA1, 'A', '1' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform A], PolicynoA2, 'A', '2' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform A], PolicynoA3, 'A', '3' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform A], PolicynoA4, 'A', '4' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform A], PolicynoA5, 'A', '5' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform B], PolicynoB1, 'B', '1' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform B], PolicynoB2, 'B', '2' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform B], PolicynoB3, 'B', '3' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform B], PolicynoB4, 'B', '4' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform B], PolicynoB5, 'B', '5' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform C], PolicynoC1, 'C', '1' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform C], PolicynoC2, 'C', '2' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform C], PolicynoC3, 'C', '3' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform C], PolicynoC4, 'C', '4' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform C], PolicynoC5, 'C', '5' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform D], PolicynoD1, 'D', '1' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform D], PolicynoD2, 'D', '2' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform D], PolicynoD3, 'D', '3' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform D], PolicynoD4, 'D', '4' FROM myTableA99 UNION ALL
SELECT RequestID, [Platform D], PolicynoD5, 'D', '5' FROM myTableA99
GO

SELECT * FROM myTableA99
GO

SELECT * FROM myTableB99
GO

EXEC sp_rename 'myTableA99', 'myTableA99_bkp'
GO

SELECT * FROM myTableA99_bkp
GO

CREATE VIEW myTableA99
AS
SELECT A.RequestID, [Platform A], [Platform B], [Platform C], [Platform D]
, MAX(PolicynoA1) AS PolicynoA1
, MAX(PolicynoA2) AS PolicynoA2
, MAX(PolicynoA3) AS PolicynoA3
, MAX(PolicynoA4) AS PolicynoA4
, MAX(PolicynoA5) AS PolicynoA5
, MAX(PolicynoB1) AS PolicynoB1
, MAX(PolicynoB2) AS PolicynoB2
, MAX(PolicynoB3) AS PolicynoB3
, MAX(PolicynoB4) AS PolicynoB4
, MAX(PolicynoB5) AS PolicynoB5
, MAX(PolicynoC1) AS PolicynoC1
, MAX(PolicynoC2) AS PolicynoC2
, MAX(PolicynoC3) AS PolicynoC3
, MAX(PolicynoC4) AS PolicynoC4
, MAX(PolicynoC5) AS PolicynoC5
, MAX(PolicynoD1) AS PolicynoD1
, MAX(PolicynoD2) AS PolicynoD2
, MAX(PolicynoD3) AS PolicynoD3
, MAX(PolicynoD4) AS PolicynoD4
, MAX(PolicynoD5) AS PolicynoD5
FROM (
SELECT RequestID, [Platform] AS [Platform A]
, CASE WHEN yGrid = '1' THEN [Policy] END AS PolicynoA1
, CASE WHEN yGrid = '2' THEN [Policy] END AS PolicynoA2
, CASE WHEN yGrid = '3' THEN [Policy] END AS PolicynoA3
, CASE WHEN yGrid = '4' THEN [Policy] END AS PolicynoA4
, CASE WHEN yGrid = '5' THEN [Policy] END AS PolicynoA5
FROM myTableB99
WHERE xGrid = 'A') AS A
JOIN (
SELECT RequestID, [Platform] AS [Platform B]
, CASE WHEN yGrid = '1' THEN [Policy] END AS PolicynoB1
, CASE WHEN yGrid = '2' THEN [Policy] END AS PolicynoB2
, CASE WHEN yGrid = '3' THEN [Policy] END AS PolicynoB3
, CASE WHEN yGrid = '4' THEN [Policy] END AS PolicynoB4
, CASE WHEN yGrid = '5' THEN [Policy] END AS PolicynoB5
FROM myTableB99
WHERE xGrid = 'B') AS B
ON A.requestID = B.RequestID
JOIN (
SELECT RequestID, [Platform] AS [Platform C]
, CASE WHEN yGrid = '1' THEN [Policy] END AS PolicynoC1
, CASE WHEN yGrid = '2' THEN [Policy] END AS PolicynoC2
, CASE WHEN yGrid = '3' THEN [Policy] END AS PolicynoC3
, CASE WHEN yGrid = '4' THEN [Policy] END AS PolicynoC4
, CASE WHEN yGrid = '5' THEN [Policy] END AS PolicynoC5
FROM myTableB99
WHERE xGrid = 'C') AS C
ON A.requestID = C.RequestID
JOIN (
SELECT RequestID, [Platform] AS [Platform D]
, CASE WHEN yGrid = '1' THEN [Policy] END AS PolicynoD1
, CASE WHEN yGrid = '2' THEN [Policy] END AS PolicynoD2
, CASE WHEN yGrid = '3' THEN [Policy] END AS PolicynoD3
, CASE WHEN yGrid = '4' THEN [Policy] END AS PolicynoD4
, CASE WHEN yGrid = '5' THEN [Policy] END AS PolicynoD5
FROM myTableB99
WHERE xGrid = 'D') AS D
ON A.requestID = D.RequestID
GROUP BY A.RequestID, [Platform A], [Platform B], [Platform C], [Platform D]
GO


SELECT * FROM myTableA99
GO

DROP VIEW myTableA99
DROP TABLE myTableB99, myTableA99_bkp
GO





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

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 13:15:41
quote:
Originally posted by revdnrdy
Why would you want to use a view on a production database? This could create a performance hit due to IO usage. At my company we only use views for querying against a reporting server..



What's the difference between table joins in a sproc as comapred to a view that isolates those joins and perhaps any business logic?

quote:

The original post seems to suggest that you want to remap data from A to B and then use B in production. Couldn't this be accomplished by simply copying data from A to B? I can think of a couple of ways to do this..



The reason is that if there are uber number of places that this table is referenced, you will have to go in and open all the code and replace it with code that can handle normalized data


quote:

...10 yr old child



...you are certaintly not to far north of that

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=43225

Sorry if I hurt your feelings...



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

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-10 : 13:49:35
how would I create a view that best suits our scenario?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-10 : 14:47:08
please first cut and paste the eample I spent (quite) awhile on....it is very cliose to what you've outlined..

BUT, What are you going to do?

Do you have a plan of action, or are you just fishing?

we don't even know the real table names

do an sp_depends TableA and tell us how many objects are affected



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

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-11 : 08:43:25
Iam not fishing at all.I really have a situation and I am trying to understand what you sent.
I dont have plan of action until I understand what you sent and try to adapt.Thank you very much for the above help
I did sp_depend on table A and it looks like there will be 13 stored procedures and 1 view which will be affected.

Go to Top of Page
    Next Page

- Advertisement -