473,473 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Mapping tables

1 New Member
i have to popuate one table(say sales) in database with the values in another table(say temp). the mapping details of sales and temp table exist in a table called mapper.

how can i populate(insert values into) sales table's fileds with temp table's fields WITHOUT using the column names of the tables, but instead i have to use the mapper table.

mapper table( SalesFieldName, TempFieldName)
Sep 7 '07 #1
4 5229
azimmer
200 Recognized Expert New Member
i have to popuate one table(say sales) in database with the values in another table(say temp). the mapping details of sales and temp table exist in a table called mapper.

how can i populate(insert values into) sales table's fileds with temp table's fields WITHOUT using the column names of the tables, but instead i have to use the mapper table.

mapper table( SalesFieldName, TempFieldName)
Compile the proper INSERT statement into a string then EXEC the string.
Sep 7 '07 #2
KritiGuleria
13 New Member
Compile the proper INSERT statement into a string then EXEC the string.



but my problem is i cannot write in the COLUMN NAMES, neither in insert part nor in values part.
i have to select colum names dynamically from mapping table.
Sep 10 '07 #3
azimmer
200 Recognized Expert New Member
but my problem is i cannot write in the COLUMN NAMES, neither in insert part nor in values part.
i have to select colum names dynamically from mapping table.
Easy, easy. When I said you should compile the statement into a variable I meant something like this (not actually tried (I cannot now) but should illustrate the point):
Expand|Select|Wrap|Line Numbers
  1. declare @columns as varchar(255)
  2. declare @sqlstatement as varchar(1024)
  3.  
  4. select @columns = columnnamecol+',' from mappingtable
  5. set @columns=left(@columns,length(@columns)-2)   ' remove trailing comma
  6.  
  7. set @sqlstatement = 'INSERT INTO datatable (' + @columns
  8. set @sqlstatement = @sqlstatement + ') VALUES (1,2)'
  9.  
  10. exec (@sqlstatement)
  11.  
Sep 10 '07 #4
KritiGuleria
13 New Member
Easy, easy. When I said you should compile the statement into a variable I meant something like this (not actually tried (I cannot now) but should illustrate the point):
Expand|Select|Wrap|Line Numbers
  1. declare @columns as varchar(255)
  2. declare @sqlstatement as varchar(1024)
  3.  
  4. select @columns = columnnamecol+',' from mappingtable
  5. set @columns=left(@columns,length(@columns)-2)   ' remove trailing comma
  6.  
  7. set @sqlstatement = 'INSERT INTO datatable (' + @columns
  8. set @sqlstatement = @sqlstatement + ') VALUES (1,2)'
  9.  
  10. exec (@sqlstatement)
  11.  

hey thanks a lot.
it worked
Sep 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jon Sequeira | last post by:
I have a question about a general approach to mapping schemas for use with SQLXML . Suppose I have a product table, which has information that's related to two groups of otherwise unrelated...
1
by: Trent | last post by:
Hello, all. I'm having problem creating subcription sets for replication on UDB DB2 Express Edition 8 fp5 on Windows 2000 Server. I could not add member to the sets on the Source-To-Target...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
0
by: Bill | last post by:
Hi, I need to take out records from one table and insert it into another identical table via a C# application. Is there a way to dynamically determine the corresponding columns of the two...
0
by: Bill | last post by:
By dynamic mapping, I meant that before the records are transferred from one table to the other(source to target), the xml file which will have the field names of the two tables mapped, is to be...
0
by: Ads B | last post by:
Hi folks! Has anyone out there come across a code generation tool that will do the following:- - read in a number of handwritten XSD files - create a set of SQL Server tables which can hold...
1
by: Ram | last post by:
Hey, I'm having a trouble mapping a connecting between 2 of my tables. We have 2 tables - the simplest "dept", "emp" tables which are mapped to 2 classes. Class Dept contains 2 properties for...
1
by: MattM | last post by:
Looking at a tutorial for Asp.Net 2.0 using Northwind, the DAL was built by dragging the tables on to an XSN to create a dataTable object for each table in the database. The BLL was then mapped for...
0
by: marcosalvadeo | last post by:
I have a problem. I created a dataset in visual studio 2005 which use tables of SQL Server Mobile. When I create insert query in the relative TableAdapter, the dataset designer maps the type...
0
by: ishakteyran | last post by:
I am İshak Teyran , the data manager of a team which attends to IBM XML Challenge Turkey , we are trying to build a dynamic web project in Rational Software Architect 7.5, WAS 7.0 , DB2 9.5 EE. ...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.