MS SQL Insert Data from One table to another

Hi guys,

After seeing the benefits one can derived in developing applications running
on sql, I have tried my hands on some small
application, but with some challenges, and I will be grateful if someone can
help me out.

I want the contents one table to be added to some specific fields in another
table. for eg.

Table 1

P_Id     pMonth     pYear     pRegistrar            pFormType
pCasetype    .....



table 2
fID        FormName
1           Land
2           Commercial
3           Defamation
....            .....

I want to insert the values of table 2 to table 1 specifically the P_Id and
Casetype and line with some global variables glo:Month = "July"; glo:Year =
2010; glo:registrar = "Rexford Gyimah" ; glo:rform = "Form A".

I want the result table to look like this after the insert

P_Id        pMonth        pYear        pRegistrar                pFormType
pCasetype
1             July                2010         Rexford Gyimah     Form A
Land
2             July                2010          Rexford Gyimah    Form A
Commercial
3             July                2010            Rexford Gyimah   Form A
Defamation

Can any help me with the right syntax for such an operation. This is one of
my challenges in this application am working on.

Thank you.

Francis
 

0
Francis
7/12/2010 8:11:57 AM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies
1685 Views

Similar Articles

[PageSpeed] 3

On Mon, 12 Jul 2010 08:11:57 -0000, "Francis Baiden"
<joebaiden1@yahoo.com> wrote:

>Hi guys,
>
>After seeing the benefits one can derived in developing applications running
>on sql, I have tried my hands on some small
>application, but with some challenges, and I will be grateful if someone can
>help me out.
>
>I want the contents one table to be added to some specific fields in another
>table. for eg.
>
>Table 1
>
>P_Id     pMonth     pYear     pRegistrar            pFormType
>pCasetype    .....
>
>
>
>table 2
>fID        FormName
>1           Land
>2           Commercial
>3           Defamation
>...            .....
>
>I want to insert the values of table 2 to table 1 specifically the P_Id and
>Casetype and line with some global variables glo:Month = "July"; glo:Year =
>2010; glo:registrar = "Rexford Gyimah" ; glo:rform = "Form A".
>
>I want the result table to look like this after the insert
>
>P_Id        pMonth        pYear        pRegistrar                pFormType
>pCasetype
>1             July                2010         Rexford Gyimah     Form A
>Land
>2             July                2010          Rexford Gyimah    Form A
>Commercial
>3             July                2010            Rexford Gyimah   Form A
>Defamation
>
>Can any help me with the right syntax for such an operation. This is one of
>my challenges in this application am working on.
>
>Thank you.
>
>Francis
> 

Hi

It is not that clear what you are  trying to do, if you posted DDL and
example data as insert statements it would be less ambiguous and give
people something to go on. See
http://www.aspfaq.com/etiquette.asp?id=5006  

How do you match rows in table1 and table2 ?

John
0
John
7/13/2010 6:29:55 AM
> I want to insert the values of table 2 to table 1 specifically the P_Id and
> Casetype and line with some global variables glo:Month = "July"; glo:Year =
> 2010; glo:registrar = "Rexford Gyimah" ; glo:rform = "Form A".


Like this?

INSERT INTO Table_1(P_Id, pMonth, pYear, pRegistrar, pFormType,
pCasetype)
SELECT P_Id, 'July' AS pMonth, 2010 AS pYear, 'Rexford Gyimah' AS
pRegistrar,  'Form A' AS pFormType, pCasetype
FROM Table_2
WHERE [insert conditions here]

brgds

Philipp Post


0
Philipp
7/14/2010 12:02:59 PM
Reply:

Similar Artilces:

SQL in Excel data
Hi all, Is there a possibility/way to run an SQL query in an excel data sheet? I have quite some data like the sample below, now i would like to have the sum of spending for each person. Like it is possible in Access. A1 B1 Field1 Field2 Chuck 12,89 Mike 23,09 Jean 9,34 Chuck 30,00 Mike 3,80 Chuck 22,00 Mike 7,23 Jean 10,55 Jean 10,75 Jean 31,45 Chuck 19,99 Result Field1 SumOfField2 Chuck 84,88 Jean 62,09 Mike 34,12 Advice would be appriciated. Cheers, Ludovic Hi You could use a formula like this ...

Two mailboxes for one user account after mailbox moved to a new server
After moving a user's mailbox from a Exchange 2003 to a new Exchange 2003 server, Outlook has listed two mailboxes with same name in the "All Mail Folders"area. The Outlook profile only has the user mailbox and no other mailboxes added to it. The user can send and recieve email just fine. The mailboxes seem to be clones of each other. New mail show up in the mailboxes at the sametime. How can I get Outlook to only show one mailbox? Any help would be appreciated, thanks, ...

How to get XML data out of an XML file
I am trying to retrieve the Parameters first or second (0, 1 ,2) node from the following XML file: <?xml version="1.0" encoding="utf-8" ?> <Robot xmlns="http://tempuri.org/RobotDefaults.xsd"> <Parameters> <Name>Decker</Name> </Parameters> <Parameters> <Name>A</Name> </Parameters> <Parameters> <Name>B</Name> </Parameters> </Robot> There will be more data than just a name for each Parameters node. Here is my code: Dim node As XmlNode = xmlDocument.SelectSingleNode("/P...

Outlook 2000 doesn't respond after downloading MS update!!
Luckily, my Outlook Express seems to work, but my Outlook 2000 will open, but if I click on a message or do Anything, it FREEZES. HELP!! I rely on calendar functions, other things. HOW could MS allow an update that screws up their own programs? I did restore - to no avail. I lent CD to someone, so can't do "repair." (Trying to get a hold of friend) Please help! I'm in process of job hunt & really need Outlook to function... Thanks, Sherry Did you recently apply SP3 for Office/Outlook 2000 and is Outlook 2000 configured in Internet Mail Only mode? If yes, you...

Form for table
Here's the problem: Access 2003, XP Pro- I have three tables that are related by primary keys. I have a table[Table QC] that has the field [EmployeeID], the data type is number--that field is linked to the autonumber primary key of the Employees Table. So far so good. I am trying to make a form that has a combo box that looks to the Employee Table to get me the drop down of the employees (Last Name, First Name). The SQL statement builds out okay, and I get the correct name config., but because the data type is a number it won't accept the data. I looked at the Northwind example and i...

Count unique values
Hi, I've some problems to count unique items (Invoice #) in a pivot table. There is the default solution "Add-a-new-calculated-column" as mentioned on http://contextures.com/xlPivot07.html#Unique, but in my case, it doesn't works. My problem is, that these values aren't in a Excel worksheet; it's a external data source - a SQL-Select via DAO/ADO. Because of that, I don't have the possibility to add a new column. Another reason is, that the pivot table should always be dynamic: Group over this field, group over another field - and always show the number of unique...

How many Server-side rules can you put on one mailbox?
I am using Exchange Server 2003 and want to setup 52 rules on one of the mailboxes, is this possible? the hardcoded limit on space for rules is 32K...i doubt you'll be able to get 52 rules on one mailbox... -- Susan Conkey [MVP] "jmareel" <jmareel@discussions.microsoft.com> wrote in message news:6ADDDCD7-948C-415F-B194-1944C9936BC2@microsoft.com... > I am using Exchange Server 2003 and want to setup 52 rules on one of the > mailboxes, is this possible? http://support.microsoft.com/default.aspx?scid=kb;en-us;147298 -- Bharat Suneja MVP - Exchange www.zenpris...

Repair SQL Corrupt database
Hi, I have a corrupt MS SQL Server 2005 database which I am trying to repair using: DBCC CHECKDB ('MYDB', REPAIR_ALLOW_DATA_LOSS) Unfortunately this does not seem to fix anything. After running the repair multiple times, I ran DBCC CHECKDB ('MYDB') WITH NO_INFOMSGS to see if it fixed the corruption, I noticed that is was returning a random amount of errors on each run. Does any know if It is the case that this database is beyond repair? If so will the best approach be to revert back to a non corrupt database backup and then roll forward using Transaction Lo...

Locking cell color while allowing data changes in cell
In excel 2000, I created an attendance worksheet for my classes.(Alphabetized names down left vertical column. Dates across top of horizontal row.) I added a different color to all cells in every other row to make for easier reading of each student's name and absences. Every other row stays with a white background. My question: I wondered if it was possible to lock row colors while allowing data to change on top of them. If a new student is added to my class in alphabetical order, the alternating color pattern is often lost. It is a pain to rechange row and cell colors. Any shortcut ...

How refresh imported data automatically?
In Excel, I've imported data into a worksheet. I know I can click Data.. Refresh Data to requery the source, but I want to be able to do it in a more automated way. Is there some sort of macro I can write when opened or something? Thanks, Ron Ron, Select the cell the data starts in, select Data/Import External Data/Data Range Properties Check the box "Refresh on file open" and anything else that needs checking off... Other than that, you could record a new Macro that selects your cell, refreshes data, and assign the macro to a keystroke, or even an icon. Beege ...

List Running Horizontally-Pivot Table Possible?
I just had a customer ask this one and I'm not so sure about it. 1) The customer has setup a list of information that is running horizontally instead of the typical list running vertically. 2) I just taught him how to do pivot tables and he wants to generate a pivot table with his "horizontal" list. 3) I know he can copy and paste special and use the Transpose feature to change the list from horizontally oriented to vertically oriented. 4) the question is: can he leave the table in its original orientation and still generate Pivot tables? I can't seem to make it work ...

Question About Missing Data
So, this is probably really easy, but I just want to ask and see if I may be missing something here. Some data on vendor numbers changed. Let’s say IBM used to have a vendor number 12345 and now it’s vendor number is 56789. I can identify IBM as IBM, but I really want to use the number, not the name. Should I set up a table that ties the numbers together, so that Access knows 12345 = 56789? Or, should I do some kind of Update Query and change all incidences of 12345 to be 56789? Or, is there some other, method, like a ‘best practices for missing data’? Thanks! Ryan--- ...

Outlook Data Files #4
I've done some reading but I'm still confused about the use of Office Outlook Personal Folders File (.pst) versus Outlook 97-2002 Personal Folders File (.pst). I understand the basic "Office Outlook Personal Folders File (.pst) to create a new Outlook 2003 .pst file. Click Outlook 97-2002 Personal Folders File (.pst) to create a new Outlook .pst file that is compatible with earlier versions of Outlook." When we have upgraded to Outlook 2003 or set up a new PC with Outlook 2003, when adding PST's you can chosse either of the two file type options and browse to chos...

New Named Range Created Each Time Data Imported into Excel via Macro
I have noticed that each time I import data into an Excel spreadsheet via a macro, a new named range (for the same range) is created. This does not pose a problem, but after a while, I'll have a huge number of named ranges that will never be used. Why does Excel name the range and how can I stop this? I noticed in the recorded macro, there was a line .Name = "drd_5". I commented this out to see what would happen, but it just renamed the range "ExternalData_5". The next one was "ExternalData_6", etc. Thanks, Carroll Rinehart You could refresh with differen...

Only one line in Money invoice
I have been using Money 2007 Home & Business to create and print invoices. This program has run with no problems for some time. However, just recently, it will only allow one item to print on the invoice. I can enter more than one item, and the invoice entry will show the additional items, but when printed only one item will show up. I have tried backing up my Money file to a spare disk, deleting the program and the associated mny and mbf files from the computer, reinstalling the program and reloading the backup. The same fault immediately occurs. Strangely, I have now installed the sam...

How do I combine two worksheets into one graph
I have two worksheets on an Excel spreadsheet. I would like to take both worksheets and place in one graph. Any suggestions? Make a chart with data from one sheet. Then copy the data on the other sheet, select the chart, and use Paste Special from the Edit menu to add the copied data as New Series. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ McPowerUser wrote: > I have two worksheets on an Excel spreadsheet. I would like to take both > worksheets and place in one graph. Any suggestions? ...

Hyper link one column to another
I would like to have my columns hyper link one another. For example: Click on B2 would take you to N2, and vice-versa. Click on C2 would take you to O2... and so on through column j linked to V. Is this possible without having to make the link for each cell? This is a timesheet template and the columns b though J are the hours and N through V are the text comments for those hours. When I copy the template to a new sheet, there will be no data in any column. I would like to be able to enter an amount or formula (=end-start) for time spent and then be able to click on that cell and hyperlin...

Copying Publisher from One computer to another
I want to copy Publisher from my old computer to my new one, but if I can't seem to locate all the files I need to make it work on the new computer. What should I do? You can't, you have to install it from the CD. -- ~~~~~~~~~~~~~~~~~~ Rob Giordano Microsoft MVP Expression "Jasmin" <Jasmin@discussions.microsoft.com> wrote in message news:7EB558F1-525D-47BD-A54B-BC62C410D79E@microsoft.com... |I want to copy Publisher from my old computer to my new one, but if I can't | seem to locate all the files I need to make it work on the new computer. What | shoul...

Reference: many to one
I have a form in which users enter information...I keep all controls locked until the user hits a command button to unlock particular bound controls. This works really well, but becomes cumbersome to code when new controls are added; e.g., adding the new control to the several event procedures attached to the form. Can anyone tell me how to refer to a group of controls once, e.g., give them a name; and then only have to refer to that name in the future? alex Alex I'm having trouble visualizing your situation. It sounds like you are describing a form that is being regularly modified....

Find what control is using a data item
I built a form, then deleted 2 columns from the source table and now I get a popup asking for the value of those 2 columns. The problem is, I don't use those columns so I need to find what on the form is refferencing the deleted columns. I have looked at the control drop down on the properties window and the tab order window and can't find a control with either one of the missing column names. How do I determine what is trying to refference the deleted columns? I found the problem, the column was still referenced in the underlying query that fed the form. "MeSteve"...

Newbie: In a CRichEditCtrl, FindText more than one occurrence?
This is a multi-part message in MIME format. ------=_NextPart_000_004B_01C36B32.6412DB00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have been looking at three books and making many C++ errors for two = day now for answers to my questions. If I can help it, I save this as my = last resort. Anyway, this is my last resort. I have two questions: 1) I have a CRichEditCtrl class. I can use the FindText function to find = the first occurrence of the substring but I don't know how to find the = second++. (Or the CString or the <st...

merging data
Hi all:) I'm new to this forum and to to Excel (2000) and not sure that I'm asking this question correctly but here is what I'm trying to do. The data on my work sheet is pasted from another sorce and includes information: name, ref #, time, date. I use this information looking up the status of an order and enter a "status note" in 5th (last) column. As the day progresses, the source that the data comes from is copied and pasted under the current list I already have going and much of the data on the lower list is a duplicate. How can I merge the to list so that I hav...

auto fill in data when changing fields
i new to crm 4 and i would like to; once i selected the account i need it to grab the main phone and put it in the phone field, and could you tell me where i need to do this, thanks -- j.hardy you can modify the mappings of the corresponding relationship "moon" wrote: > i new to crm 4 and i would like to; once i selected the account i need it to > grab the main phone and put it in the phone field, and could you tell me > where i need to do this, thanks > -- > j.hardy ...

Pivot Table data values
I need make a pivot table using the values as the data. I used to be able to do this, but now it only sums, counts or calculates. Is there a way to return the data values? ...

How can I use a form (Excel) to add a column of data to the right.
How can I use a form (Excel) to add a column of data to the right of a list? It's a simple matter to add a column to the left of a list by writing a macro that inserts a column and then pastes the values. However I want to have the data pasted on the right of a list, if only so that I can easily run a chart from it. ...