Solved

Access copy row querry

Posted on 2003-12-02
7
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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 250 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 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