GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Jul-2006, 02:47
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,095
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough

SQL Question


I need a little help with this I have two database I need to take data from 4 columns in one database and then insert that into 1 column in another database?

Does anyone have any idea about how I could do this?
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #2  
Old 07-Jul-2006, 09:37
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


Are the 'other 4 columns' in the same table?

it would be something like this lexicon, with the target database in use...
Code:
INSERT INTO <targetTbl> SET <targetField> = ( SELECT concat( f1, f2, f3, f4 ) FROM <otherDB>.<table> WHERE <condition> ); // going to one field, the result must resolve to one column.
Note that the concat() above has no separators, which will jam the fields together, so you would need to add spaces, or comma's into the concat where needed.

If the four fields are from multiple tables, then the FROM clause would need:
<otherDB>.<table1>, <otherDB>.<table2>, etc. to resolve the various fields.

Let us know how it goes!
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 07-Jul-2006, 21:05
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,095
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough

Re: SQL Question


Thank you but I need to ask something else, This is an ASP script with MS Access as its database I was told that SQL would be the way to do this (Why I posted here. ) But I need find out if may this is the best way.

What I have is I have a database Netview data look like this in the table:

col_store_number col_device col_ticket col_assigned_to col_resolved
002 ISP 123456 Help Desk No
003 LMS 123456 Telcom Yes
004 Router 123456 Help Desk No
005 Store 123456 Telcom No
006 CC 123456 Help Desk Yes

Now for all of the stores that the col_resolved = No I need to store the data something like this

Store: 002
Device: ISP
Ticket: 123456
Assigned To: Help Desk

I need it to format this data like this of each row that col_resolved = No
Then I need to insert it into a column in and already existing record a another database

The Turnover database looks like this:

col_id col_main col_dist col_netw col_misc
12 Mainframe problems Dist Problems Network Problems Misc Problems

There will only been one record in this database at a time I need to take the 4 columns in the netview database adn then put them in the Turnover database in the col_netw

Yes all of the 4 columns are in the same table.

I hope this makes since.

Thanks Again
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #4  
Old 08-Jul-2006, 21:42
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


Are you able to link the required table in the Netview database to the Turnover database?

If so, I came up with this from your sample data:
(this may not be the most elegant solution, but it works (I have Access 2k). I tried using a similar query like post #2 (assuming MySQL, based on this forum), but Access kept complaining about needing 'EXISTS' in the FROM clause. I tried a few different ways, but I could not get around the error(s), even after following some of their examples )
Code:
UPDATE TurnoverData SET col_netw = "Store: " & DLookup("[col_store_number]","netviewdata","[col_store_number]=2") & " Device: " & DLookup("[col_device]","netviewdata","[col_store_number]=2") & " Ticket: " & DLookup("[col_ticket]","netviewdata","[col_store_number]=2") & " Assigned To: " & DLookup("[col_assigned_to]","netviewdata","[col_store_number]=2");
You would have to modify it, though, to be able to pass in a variable store number (via a loop or some other function call). Plus, there are no newlines added between the entries.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 08-Jul-2006 at 22:36.
  #5  
Old 08-Jul-2006, 21:51
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


Oops, I will need to rework that a little, I missed the part about 'col_resolved = No'. I was driving off the store number. The change might actually be more significant, and possibly more elegant.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #6  
Old 09-Jul-2006, 21:43
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


Ok, after hearing the "loud-pop"...

That turned out to be a simple append query, but still requires being able to link Netview's specific table (that has the 4 fields) into Turnover database for this example.

The query would then look like this:
(in Access, open a blank query, switch to SQL view, paste the following SQL)

Code:
INSERT INTO TurnoverData ( col_netw ) SELECT "Store: " & [col_store_number] & " Device: " & [col_device] & " Ticket: " & [col_ticket] & " Assigned To: " & [col_assigned_to] AS col_netw FROM NetviewData WHERE (((NetviewData.col_resolved)="No"));

After pasting the SQL, switch the view back to design mode to see the graphical layout. Let us know how it goes!

-- Oh, before I forget, the information in the example is separated by spaces when it is inserted into the 'col_netw' field.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #7  
Old 10-Jul-2006, 20:02
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,095
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough

Re: SQL Question


That grab what I needed and got it formatted the way I need. Now I have one more question would it be possiable to have it up date a record that was already there?

Thank you again for all the help.
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #8  
Old 10-Jul-2006, 20:18
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


Yes, but how will be updated? [based on what criteria]

You mentioned earlier (in post #3) that there is only one record at a time? (I assume this means for each store) -- so does this mean that the update is a delete?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #9  
Old 10-Jul-2006, 21:39
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,095
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough

Re: SQL Question


Quote:
Originally Posted by TurboPT
Yes, but how will be updated? [based on what criteria]

You mentioned earlier (in post #3) that there is only one record at a time? (I assume this means for each store) -- so does this mean that the update is a delete?

Ok sorry I meant rather than Inserting into the turnover col (col_netw) could I set this to update a record that is already there. in post 3 I meant the turnover database has only one record in it at one time the netview database can have multi records in it at one time.

so like when I run the query that you gave it works but if the netview database have 3 record in it it will insert 3 new records in the turnover database could this be fixed to just update the record that is already in the turnover database?
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #10  
Old 11-Jul-2006, 07:04
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: SQL Question


I understand about updating a turnover record already there, (after a prior insert), but what will be the update criteria? Here's more info...

The previous query will add (three records based on the previous sample), and it will always add (append/[insert]) as it stands...

Now, for the update part, in the turnover table, say you have previously already 'inserted' the three stores. How (or what) will be updated in the turnover table? The same field from the insert query? Delete a store whose 'resolved' has changed to 'Yes'? That's all I'm trying to understand. Then we can work the update part.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
functions seems not to exit from a certain code block jaro C Programming Language 3 22-Mar-2006 00:08
Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 lyuboe MySQL / PHP Forum 0 11-May-2005 05:31
non-member function question crq C++ Forum 1 03-Feb-2005 22:59
Simple question on arrays--please help! brookeville C++ Forum 16 18-Nov-2004 00:23
DiscountASP.NET Launches SQL Reporting Services dasp Web Hosting Advertisements & Offers 0 19-Oct-2004 18:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:21.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.