?
Solved

Access copy row querry

Posted on 2003-12-02
7
Medium Priority
?
497 Views
Last Modified: 2008-02-01
I have a table called "controls" and "roles". They are the exact same structure.
Now i need to copy the values in the row of table "roles" (with username "default") to the "controls" table with a new username im getting from the parameter. Any ideas how to do this in 1 access querry ?!


PARAMETERS [@username] Text ( 50 );
DECLARE  [@top] text (255), [@left] Text  (255),[@middle] Text (255), [@right] Text (255),[@bottom] Text (255);

SELECT  [@top] = Roles.[top], [@left]=Roles.[left], [@middle]=Roles.[middle], [@right]=Roles.[right], [@bottom]=Roles.[Bottom]
FROM Roles
WHERE Roles.Username = "default"

INSERT INTO controls Values  SET controls.username = [@username], controls.[top] = [@top], controls.[left] = [@left], controls.middle = [@middle], controls.[right] = [@right], controls.bottom = [@bottom]
0
Comment
Question by:zinno
  • 4
  • 2
7 Comments
 
LVL 5

Expert Comment

by:morpheus30
ID: 9862665
INSERT INTO Controls (Top, Middle, Right, Bottom, UserName) SELECT Top, Middle, Right, Bottom, UserName, [Enter UserName] FROM Roles
0
 
LVL 5

Assisted Solution

by:morpheus30
morpheus30 earned 750 total points
ID: 9862673
Sorry, I forgot the where statement

INSERT INTO Controls (Top, Middle, Right, Bottom, UserName)
SELECT Top, Middle, Right, Bottom, UserName, [Enter UserName]
FROM Roles
WHERE UserName = "default"

0
 
LVL 23

Accepted Solution

by:
heer2351 earned 750 total points
ID: 9862701
Looks like you have a .adp, correct?

This should do the trick:

PARAMETERS [@username] Text ( 50 );
INSERT INTO controls (username, top, left, middle, right, bottom)
SELECT [@username], [top], [left], [middle], [right], [Bottom]
FROM Roles
WHERE Username = "default"
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 23

Expert Comment

by:heer2351
ID: 9862708
Sorry morpheus30 did not see your code until I posted mine, only difference that I declare the parameter first.
0
 
LVL 9

Expert Comment

by:svenkarlsen
ID: 9862752
And on first given opportunity, you should change the name of your table "Controls", - it is a critical word to use for naming objects in Access, as it has explicit meaning in certain relations.

Sven
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9862823
Oh dude...

I misunderstood the question: Any ideas how to do this in 1 access querry ?!

I was thinking you were trying to convert T-SQL into native Access SQL used by .mbd files.  My solution won't work if you're using an .adp file.  heer2351's solution should work for you there...

0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9862945
If you want to save it as a query (Stored Procedure) in your Access .adp file, you could copy and paste the following SQL statement

INSERT INTO Controls (Top, Middle, Right, Bottom, UserName)
SELECT Top, Middle, Right, Bottom, UserName, @UserName
FROM Roles
WHERE UserName = 'default'
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question