Copying data from one table to another table




I need to copy data from one table into another table. The field names are NOT the same:

I need to INSERT

Table 1 fields:
cdescurl
cname
cdescription
cimageurl
category
cprice

INTO

Table 2:
product_url
name
description
image_url
category
price

How do I do this Thank you in advance for any help you can give me!
Posted On: Friday 26th of October 2012 12:05:12 AM Total Views:  291
View Complete with Replies

RELATED TOPICS OF Microsoft SQL Server PROGRAMMING LANGUAGE




Populating a database with data from db if a value exists

Hi all, I have a table where I want to populate it with data (certain fields) from another table. But I only want to populate the table if there is data in a certain field in the table I wish to get the data from. How exactly would I do this test Would an I have to perform an IF statement to test if the field contains a value first
VIEWS ON THIS POST

119

Posted on:

Friday 26th October 2012
View Replies!

dynamic/variable database name

Hi I have a trigger which retrieves database names from a table. I need to use this retrieved database name in another sql insert statement as a variable e.g. set @mydbname = Select .... from.. (to get the database name) then.. insert into @mydbname.dbo.emplTable At the moment it reads @mydbname as the string "@mydbname" not the value the variable holds I need the database name as a variable because i have to write to the correct database (there are 15)
VIEWS ON THIS POST

188

Posted on:

Friday 26th October 2012
View Replies!

Help with MS SQL Server - updating data from 2 tables

Hi all, Please forgive me, but I'm new to MS SQL Server and I have few questions. First of all I'd like to know if there is a way to update one table with the data from another. Let's say I have 2 tables. TableA table contains the voucher numbers; TableB table contains the image numbers. Is there a way to merge Voucher numbers from TableA table to Image numbers in TableB table if we assume that there is a primary key Voucher Number in both tables If yes- what would be the query structure for that Please forgive me if you think that this question is silly, I have to say I'm not just new to SQL I'm VERY new to it Thank you in advance.
VIEWS ON THIS POST

328

Posted on:

Friday 26th October 2012
View Replies!

Will database shrinking affect the data?

Hi all, does the shrinking of the database affect the data in the database, such as will it change the data, or deleting the data away Thanx
VIEWS ON THIS POST

140

Posted on:

Friday 26th October 2012
View Replies!

Import excel data through ASP page into MS SQL database

I'm working on a warranty database for my company. Each week we receive an excel file with all of the new warranty returns from GM, Ford and such. What I want to do is have a user go to a web page select the excel file and have it import into MS SQL. Currently they e-mail the file to me and I import it with a DTS pacage I made. I realize the excel file needs to be formatted, X number of columns with specific names and data type, but how do I import it into SQL \t\t Any ideas on how to start or a pointers in the right direction would be much appreciated.
VIEWS ON THIS POST

142

Posted on:

Friday 26th October 2012
View Replies!

Shrinking of database and backup

Hi all, I am new to the backing up and shrinking of the database. so i need some help here.. How does the shrinking of the database help in terms of the database performance How long does it take to shrink and backup a database with 4GB of data Thanx alot...
VIEWS ON THIS POST

139

Posted on:

Friday 26th October 2012
View Replies!

copying data from on machine to another machine

, Am new to Sql . i need to copy the database from one machine to another machine. Both machines are not on network. Those two are individual machines and having sql server on both machines. I want to upload the data. So can any one help me out with this pls
VIEWS ON THIS POST

119

Posted on:

Friday 26th October 2012
View Replies!

Function not returning all the data, just some

I've put together a "getvalues" function to return specific information from a table or query. I pass it a list of requested fields separated by a pipe | character. The subroutine splits the fields into an array and gets the data from the fetched record, and puts together a data return variable filled with the specific data, again separated by a pipe. The record is fetched fine but the data is not accessed from it correctly. It does work fine in Access but not SQL! The basic function works like this call returndata("data1|data2|..." function returndata(requestedfields) requestedfieldarray = split(requestedfields,"|") for i = 0 to ubound(requestedfieldarray) builddata = builddata & record(requestedfieldarray(i)) & "|" next returndata = builddata end function some of fields come back fine, some do not. I also find that if I hit each field early in the function For Each objField In record.Fields scratchdata = objfield.value Next Then the function works fine. But I'd rather not use that overhead to make things work. I'm just upgrading from Access to SQL but that shouldn't have anything to do with it (I think). Anybody have any thoughts\t
VIEWS ON THIS POST

127

Posted on:

Friday 26th October 2012
View Replies!

data amount selected.

Hi all, is it possible to cout size of data selected form mssql database table for each databse user. Lets say Scott seleceted 100 rows from table tiger which is 50Kb. Could use sample statement
VIEWS ON THIS POST

118

Posted on:

Friday 26th October 2012
View Replies!

joining a view to match main data in search query

I am currently building a telephone directory, i'm at the stage where I have the search functions runing smoothly. Except the way I have the database set up is that the main table holds the business type as a numeral which was entered from another table with coresponding names. I have built views to tie these two tables together. Now once a person searchs the listings they currently recieve a page of results, it is here that the problem occurs. I need to to in my sql statment tie the main table of data to the view to pull the business type name out instead of the business type numeral which is contained within the main data table. Here is my current Sql Statement: SELECT * FROM dbo.MAIN, dbo.VIEW_BUSINESS_NAME WHERE ENTRY_TYPE LIKE 'varSearchType' AND LAST_NAME LIKE '%varName%' AND INITIAL LIKE '%varInitial%' AND STREET_NAME LIKE 'varStreet' AND STATE LIKE 'varState' AND REGION LIKE 'varRegion' AND BUSINESS_TYPE LIKE 'varBusinessType' AND dbo.VIEW_BUSINESS_NAME.Expr1 = dbo.MAIN.BUSINESS_TYPE ORDER BY LAST_NAME It is being put together in dreamweaver mx. This is returning a multiple list of the one business repeated for as many listings as there are for that business type! Hope this makes sense it's very early in the morning.
VIEWS ON THIS POST

210

Posted on:

Friday 26th October 2012
View Replies!

ODBC -- connection to database failed

all, Our last IT person created an intranet website with .asp and has linked an ODBC with SQL Server 2005 Query. Here is how it's suppose to work: there is a page where employees can input an order# and it's suppose to search the ODBC. Instead of searching the following error appears on the page: "Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Microsoft Access Driver] ODBC--connection to 'MAXDAT' failed. /home/plannedshippingresults.asp, line 49" However if I go to the System DSN from Administrative Tools, I can test the connection and it works. Here is the Code he wrote for the plannedshippingresults.asp page (The Italicized/Underlined part is Line 49): Any help would be greatly appreciated. I just started messing with this 2 days ago, and im not very fluent with ODBC, SQL, or .ASP. If you need more information, please ask.
VIEWS ON THIS POST

159

Posted on:

Wednesday 7th November 2012
View Replies!

Problem putting a DateTime variable into a datetime database field (SQL Server 08, VS

For a university project I am creating a basic car hire website. ASP.NET is all new to me, so if you could keep replies simply explained I'd appreciate it! For the final stage of the car hire process, I take variables stored in sessions: string theUser = User.Identity.Name.ToString(); DateTime pickUp = Convert.ToDateTime(Session["pickUp"]); DateTime dropOff = Convert.ToDateTime(Session["dropOff"]); string carReg = (String)Session["carReg"]; double pricePerNight = Convert.ToDouble(Session["carPrice"]); double totalPrice = noOfDays * thePricePerNight; to insert into the Hire table, where the datatypes are as follows: UserName - varchar(MAX) RegNo - varchar(50) PickUpDate - datetime ReturnDate - datetime Price - money But when I execute the insert statement, I get the following error: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. My code for inserting into the database is as follows: //Add details to Hire table string connectionString = WebConfigurationManager.ConnectionStrings["AdminCarsConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); con.Open(); SqlCommand cmd; string query = "INSERT INTO Hire (UserName, RegNo, PickUpDate, ReturnDate, Price)"; query += "VALUES ('" + theUser + "', '" + carReg + "', '" + dtPickUp + "', '" + dtDropOff + "', '" + totalPrice + "')"; cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); lblCust.Visible = false; lblPrice.Visible = false; btnConfirm.Visible = false; lblHire.Text = "The process is complete."; I experimented by changing the datatype in the table to varchar, and inserting string values of the dates instead and that worked perfectly - however I need to keep these values as datetime, because of a query that checks for time clashes at an earlier stage in the hire process, which uses the datetime values in the Hire table (this works just fine, using the datetime variables from the session). Do you have any advice on how I could solve this problem The values that I am trying to insert are datetime type, and the field I want to insert them into is datetime type, so I don't know why it has a conversion problem. I hope someone can help soon because this is so close to being finished, and my deadline is in two days...
VIEWS ON THIS POST

162

Posted on:

Wednesday 7th November 2012
View Replies!

One or multiple databases for multiple apps that share data?

It sounds like your database is not getting hit very hard, so you probably don't need to worry about it too much. You can always scale the hardware if you need to. If it does get to the point that a single server (or cluster of servers) can't handle the load, You can do something like this: 1. Separate the distinct application databases to their own servers 2. create a single server for the common structures. 3. Use replication or SSIS to push changes to the common database out to the application databases. 4. Any changes to the common database should occur in the main one, not the copies--that way there is only one source for the data and the rest can be wiped and replaced if they get out of sync. Fairly complex, but if you can't get acceptable performance any other way, it may be worth it.
VIEWS ON THIS POST

123

Posted on:

Wednesday 7th November 2012
View Replies!

Grant permissions on the database

, i am using SQL Server 2005. i have created a database by name database_Lakshmi. i want to grant all privileges on my database to another user. for that i have written a query GRANT ALL PRIVILEGES ON database_Lakshmi TO developer IDENTIFIED BY 'developerPassword' when i try executing the query the error message that i get is........ Incorrect syntax near 'IDENTIFIED' Could somebody please let me know how to rectify it.
VIEWS ON THIS POST

122

Posted on:

Wednesday 7th November 2012
View Replies!

Insert image into SQL database column

- I am trying to update an existing row in a table by inserting a jpg or gif image into a column called Photo. The SQL data field is set as image. When I build, I don't get any error messages but the upload doesn't work. I modified code from the MS site (streaming BLOBS page) I would really appreciate troubleshooting help with the code below or an alternative approach.
VIEWS ON THIS POST

193

Posted on:

Wednesday 7th November 2012
View Replies!

Retrieve data based on two different date fields

Hi , I tried the following sql query to retrieve data from two different date fields in my vb6 application. but the 0 data is retrieved. please help me. The query is: rs.open "select product1 from table1 where fromdate=#" & dt1 & "# and todate=#"& dt2 & "#", con,1,3
VIEWS ON THIS POST

121

Posted on:

Wednesday 7th November 2012
View Replies!

Transfer data between two tables in a database

Hi all, I am using MsSQL 5.0 server database. I need to transfer the data from one table to another within a SQL database based on the particular time interval. Is it possible to transfer data among the tables a database automatically. Please help me.
VIEWS ON THIS POST

171

Posted on:

Wednesday 7th November 2012
View Replies!

Getting no data on my web page

I'm having problems getting data from a db. I'm using a script I've used many times only this time the page is coming up fine with no problem. I get no error messages and no data. The only difference I see this script...is some of my field names are multiple words and there are a lot of blanks in this field within the db. any ideas anyone I do the query.....................
VIEWS ON THIS POST

104

Posted on:

Wednesday 7th November 2012
View Replies!

copying database

how to use SQLDMO to copy a database to a new database (allow custom path) with all the tables, data ,view , relationship (everything) exactly as the 1st database
VIEWS ON THIS POST

124

Posted on:

Wednesday 7th November 2012
View Replies!