?
Solved

Need help constructing SQL query with subquery

Posted on 2008-11-07
6
Medium Priority
?
213 Views
Last Modified: 2012-05-05
I need to create a view that will insert data into a table using the id from a record in another table...Here's my data setup:

WorkflowRules table
WKRL_RULEID | WKRL_CAPTION
5                    |  Escalate
6                    |  Test

WorkflowActionLinks table
ACLI_ACTIONLINKID   | ACLI_ACTIONGROUPID
1                                     5
2                                     5

select * from workflowrules where wkrl_caption = 'escalate'

then use the WKRL_RULEID (record 5) to INSERT into individual records into the WorkflowActionLinks table-- the ACLI_ACTIONGROUPID and WKRL_RULEID are the tied keys in the relationship.  So, using one SQL statement per INSERT into the WorkflowActionLinks, how can I create an INSERT statement with a subquery using my SQL query above?

0
Comment
Question by:saturation
  • 3
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 total points
ID: 22909317

did you mean something like this..

INSERT INTO WorkflowActionLinks (ACLI_ACTIONLINKID, ACLI_ACTIONGROUPID)
SELECT SomeID, WKRL_RULEID
FROM WorkflowRules
WHERE WKRL_CAPTION = 'escalate'
0
 

Author Comment

by:saturation
ID: 22909376
Almost, but it uses the WKRL_RULEID from the other query as the ACLI_ACTIONGROUPID.
0
 
LVL 26

Expert Comment

by:tigin44
ID: 22909384
This query does you what you mentioned.. if you something different can you explain more details...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:saturation
ID: 22927680
Well, the statements above are separate...I need to take use the ID from the first select statement and use that ID as the data forACLI_ACTIONGROUPID on the INSERTing into WorkflowActionLinks.  Is it possible?
0
 
LVL 26

Expert Comment

by:tigin44
ID: 22934212
can you explain what you want clearly?..
0
 
LVL 41

Expert Comment

by:Sharath
ID: 22935258
Your requirement is not clear. As tigin44 mentioned, the query should work for you. If you want more details on what are all the ways to INSERT data, you can refer msdn.microsoft.com
http://msdn.microsoft.com/en-us/library/ms174335.aspx 
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

579 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