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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Critical Insert Query using two tables

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-07-15 : 13:17:31
Table1
-----
UserID
UserName
PhoneNumber

Table1 Values
---------
1, Sriram, 9940612345
2,Kalai,9940612346
3,Ganesh,9940612347
4,Das,9940612348

Table2
-----
UserID
DeptID
AddressLine1
AddressLine2
City
State
Zip

Table2 Values
----------
1,21,45,Ambala Road, chennai,TN,600083
1,22,15,Suchi Road, chennai,TN,600084
1,23,56,Mount Road, chennai,TN,600076
2,21,12,Varun St, Madurai,TN,400083
2,22,65,Peepee Road, Selam,TN,500066
2,23,96,Main Road, Trichy,TN,556880



Table3 Structure
------------
UserID
UserName
PhoneNum
Dept21AddressLine1
Dept21AddressLine2
Dept21City
Dept21State
Dept21Zip
Dept22AddressLine1
Dept22AddressLine2
Dept22City
Dept22State
Dept22Zip
Dept23AddressLine1
Dept23AddressLine2
Dept23City
Dept23State
Dept23Zip


I need a Query to Insert the Values in Table3 using Table1 and Table2.
Consider all the columns as VARCHAR.


Regards,
Kalaiselvan R
Love Yourself First....

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-07-15 : 13:22:10
Oh my! Do not create a denormalized table like that. Why do you want to do this?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-07-15 : 13:29:03
Ya i knew that creating Denormalized table is no use. But its my Client requirement. They required this table for Each Department's Address for Each users in a single table.
Please help me in this.

Regards,
Kalaiselvan R
Love Yourself First....
Go to Top of Page
   

- Advertisement -