Question

Cfquery and array problem

Asked by: erikTsomik

I got a little problem here. I have a query and I am trying to build an array to populate all the fields in to the array.

Then i need to  check if the person is in the folowing  list of jobcodes <cfset VPofOps="8074,60851">
If it is do the insert  
The code is below

<cfquery name="qry_getDescription" datasource="xxxxxx">
		Select * from OrgUnitLocation
<!---		inner join Location l on l.OpUnit=OrgUnitLocation.OpUnit--->
where OpUnit='50029'
		order by JobDescription
	</cfquery>
	<cfset myArr = ArrayNew(1)>
	<cfset VPofOps="8074,60851">
	<cfset VPSales ="5655,7080">
	<cfset AreaVP = "8070,8073">
 
	
	<cfset AMofOps = "7072">
	<cfset AMSales = "7073">
	<cfset AMDRC = "1130">
	
	
	<cfloop query="qry_getDescription">
		<cfset myArr[currentrow][1]= OpUnit>
		<cfset myArr[currentrow][2]= Employeeid>
		<cfset myArr[currentrow][3]= First_name>
		<cfset myArr[currentrow][4]= Last_Name>
		<cfset myArr[currentrow][5]= JobDescription>
		<cfset myArr[currentrow][6]= JobCode>
	</cfloop>
	
		<cfloop query="qry_getDescription">
			<cfset lOpUnit = myArr[1]>
			<cfset lEmployeeid = myArr[2]>
			<cfset lFirstname = myArr[3]>
			<cfset lLastName = myArr[4]>
			<cfset lJobDescription = myArr[5]>
			<cfset lJobCode = myArr[6]>
		
		</cfloop>

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-13 at 12:14:11ID24406171
Tags

Cold Fusion

Topics

ColdFusion Application Server

,

Cold Fusion Markup Language

Participating Experts
2
Points
500
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Converting CF Array to JS Array?
    Ok I need a Javascript Array. And Im trying to populate it via information from a CF Array (Maybe). Ok Im trying to pull one column under a table out, and store it into a javascript Array, Im sorta familiar with Arrays in CF, but don't know how to pupulate an array but pullin...
  2. Populate array from query
    I was wondering if someone could help me with populating an array from a query, I am new to javascript, and am a little lost. I am designing a website in coldfusion and need to populate a array with this query. <CFQUERY NAME="getCompParts" DAASOURCE="carniv...
  3. Urgent: How to store the values from cfquery into an array?
    Hi Experts, How to store the value from cfquery into an array? And then retrieve it according to what radio button is selected. (Each of the radio buttons should represents 1 item in arrray) More points will be added for quick and accurate answer. Thanks.
  4. Storing a query to an array
    How would you Query something (say something easy like - SELECT bookName FROM BOOKS) and then store the values into an array? I want to then use the array to populate a combo box. thanks, jim

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: _agx_Posted on 2009-05-13 at 14:57:19ID: 24380106

Which field relates to VPofOps,  lEmployeeid or lJobCode?

I do not see any insert code. Can you explain what you need there? Does it insert have to be done using the arrays, or can you just do a separate query:

<cfquery name="addTable" datasource="xxxx">
        INSERT INTO SomeTable (....)
        SELECT  Columns
        FROM    OrgUnitLocation
        WHERE OpUnit='50029'  
        AND     lEmployeeid  IN ( 8074,60851 )
</cfquery>

 

by: gdemariaPosted on 2009-05-13 at 19:54:33ID: 24381451

You are defining a ONE dimensional array

 <cfset myArr = ArrayNew(1)>

But trying to use a TWO dimensional array...

<cfset myArr[currentrow][1]= OpUnit>

I suggest using a structure and array, its a lot clearer to refer to a variable as OpUnit than it is as "1" ...

It would look like this..   I think it's easier...

<cfset myArr[currentrow] = structNew()>
<cfset myArr[currentrow].OpUnit  = OpUnit>
<cfset myArr[currentrow].Employeeid= Employeeid>



Regarding checking the JobCode....

<cfloop query="qry_getDescription">

  <cfset VPofOps="8074,60851">
  <cfif listFind( VPofOps, qry_getDescription.JobCode)>
     .... YES, it's on the list....
  <cfelse>
     ... NO, job code is NOT on the list
  </cfif>



 

by: gdemariaPosted on 2009-05-13 at 19:55:15ID: 24381454

Oh, and I agree, however, with agx.   If you can just do it in an INSERT/SELECT query, that would be the easiest way...

 

by: erikTsomikPosted on 2009-05-13 at 21:25:52ID: 24381726

the task that I am trying to achieve is the following . I have a DB which has employeeid,jobCode,jobdescription. What i need to do :

1.Get everybody whose jobCode is 60851 or 8074. and insert into the region1 table.
The same table has columns AVPEmpID and SManagerEmpID.
So the next step is to get SmaNagerEmpID (jobCode is 5655 or 7080) and Update the same Table where regionID is the Identity key from the previous insert.

The sample data:to get people: (for 1 locationID I have over 100. For the sample sake give only 1):
OpUnit EmpID FName Lname JobDescription JobCode
6 1 J D Human Resources Director 30090
6 5 C Z Area Sales Manager 7073
6 7 S K Executive Director 8050

 

by: gdemariaPosted on 2009-05-14 at 07:08:46ID: 24385171

> Get everybody whose jobCode is 60851 or 8074. and insert into the region1 table.

This seems like agx's example...

insert into region1 table (columns?)
 select ???  from employee where jobcode in (5655,7080)

> The same table has columns AVPEmpID and SManagerEmpID.

which table?   Region1 or Employees ?

>  So the next step is to get SmaNagerEmpID (jobCode is 5655 or 7080)

From which table?  With what where clause?

> and Update the same Table where regionID is the Identity key from the previous insert.

Update the employee table using the region ID ?  
So you have a foreign key in the region1 pointing to employees and a foreign key in employees pointing to region1?



 

by: gdemariaPosted on 2009-05-14 at 09:33:23ID: 24386708

Ok Erik, let me help you ask a question. First, you need to clearly say what your tables look like, then you need to clearly state your objectives in relationship to those tables. I am still trying to put together these two things. So please correct the information below....



This is the (no name) table, so we'll call it EMPLOYEES

EmpID --- this is the primary key
OpUnit
FName
Lname
JobDescription
JobCode


This is the REGION1 table...

-- There is no Primary Key in this table
ManagerEmpID -- this is a foreign key to the Employee Table
SMAnagerEmpID -- this is a foreign key to the Employee Table
AVPEmpID -- this is a foreign key to the employee table


This is the OrgUnitLocation table...

It has this data:
50029 101469 John Smith Director 7523

It has no column names
but that doesn't matter because we don't use this table anyway




----------- Objective -------------

1) I want to insert into REGION1, column ManagerEmpID (I'm just guessing here) the EMPLOYEE ID for all EMPLOYEES where the JOBCODE is either 60851 or 8074.

2) I want update the REGION1 table by setting the SmaNagerEmpID to the same as ManagerEmpID but only for employees who have a job code of either 5655 or 7080

3) I have no idea why I even mentioned the OrgUnitLocation Table. Just thought I would share it...

 

by: erikTsomikPosted on 2009-05-14 at 09:54:34ID: 24386908

to clarify all this .
I have txt file where from which i upload the data into OrgUnitLocation. THe OrgUnitLocation has the following structure:
OpUnit, Employeeid,First_Name,Last_name,JobDescription,JobCode -- there is no primary keys

There is a region1 table where I need to insert/update the data from the OrgUnitLocation. The region1 table has the following structure:
RegionID-primary key
Name (will consists of last name's of the managerEmpID,SmanagerEmpID,AvpEmpID- ; separated)
ManagerEmpID
SManagerEmpID
AvpEmpID

Objective:
1.First every time it runs I need to delete all data from region1 table
2.Then find people who has jobCodes 8074 or 60851. (ManagerEmpID)
3.find people who has jobCodes 5655 or 7080 (SmanagerEmpID)
4.find people who has jobCodes 8070 or 8073 (AvpEmpID)

The region1 table should looks like this
3948 Jones;A 49858 3735 59195
3949 Flintstone;Rubble; 503638 509838 44443
3950 Smith;Smith;Ri 101484 101480 101484
3951 Slate;Draper;Char 42605 87348 53163

The OrgUnitDate is attached in the file. And the code that i came up with is below



<cfsetting requesttimeout="9000">
<cfquery name="qry_getDescription" datasource="xxxxx">
		Select * from OrgUnitLocation
		where  jobCode in ('8074','60851')
		order by OpUnit
	</cfquery>
	<cfparam name="holdRegionID" default="0">
		<CFQUERY name="EraseAreas"  datasource="XXXXX" >
				Delete  from Area1
			</cfquery>
			<CFQUERY name="EraseRegions"  datasource="XXXXXX" >
				Delete  from Region1
			</cfquery>
			<cfoutput query="qry_getDescription" group="OpUnit">
				<cfif qry_getDescription.JobCode eq 60851 or qry_getDescription.JobCode eq 8074>
						<CFQUERY name="GetRegion"  datasource="XXXXX">
								select * 
								from Region1 r
								where 	r.ManagerEmpID = #EmployeeID#
						</cfquery>
							<cfif GetRegion.recordcount eq 0>
								<!---insert into region Table managerEmpID--->
									<CFQUERY name="qry_insertManger"  datasource="XXXXXX">
										INsert into region1 (name,ManagerEmpID) values ('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#)
									</cfquery>
										<CFQUERY name="GetRegion2"  datasource="xxxxx" dbtype="ODBC">
											select * 
											from Region1 r
											where r.ManagerEmpID = #qry_getDescription.Employeeid#
										</cfquery>
										<cfset holdRegionID = GetRegion2.RegionID>
									<cfquery name="qry_getDescription2" datasource="XXXXX">
										Select * from OrgUnitLocation
										where  jobCode in ('5655','7080') and OpUnit in ('#qry_getDescription.OpUnit#')
										order by OpUnit
								</cfquery>
											<cfloop query="qry_getDescription2">
												<cfif qry_getDescription2.JobCode eq "5655" or qry_getDescription2.JobCode eq "7080">
													<CFQUERY name="qry_insertManger"  datasource="XXXXX">
														Update region1 set SManagerEmpID = #qry_getDescription2.Employeeid# where regionID = #holdRegionID#
													</cfquery>
												</cfif>
											</cfloop>
											<cfquery name="qry_getDescription3" datasource="XXXXXXXX">
												Select * from OrgUnitLocation
												where  jobCode in ('8070','8073')
												order by OpUnit
											</cfquery>
											<!---get all AVP--->
											<cfloop query="qry_getDescription3">
												<cfif qry_getDescription3.JobCode eq "8070" or qry_getDescription3.JobCode eq "8073">
													<CFQUERY name="qry_insertManger"  datasource="XXXXXX">
														Update region1 set AVPEmpID = #qry_getDescription3.Employeeid# where regionID = #holdRegionID#
													</cfquery>
												</cfif>
											</cfloop>
									<!---if there is a record then look for the Sales manager--->
								</cfif>
				</cfif>
											
				</cfoutput>
			Complete
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:

Select allOpen in new window

 

by: gdemariaPosted on 2009-05-15 at 07:48:57ID: 24396271

Ok, that helped a lot.  Here's the thing I am struggling with...


Here you are adding ONE record to your REGION table...

<CFQUERY name="qry_insertManger"  datasource="XXXXXX">
     INsert into region1 (name,ManagerEmpID) values ('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#)
</cfquery>


But here, you are updating this one record again and again...

<cfloop query="qry_getDescription2">
      <cfif qry_getDescription2.JobCode eq "5655" or qry_getDescription2.JobCode eq "7080">
           <CFQUERY name="qry_insertManger"  datasource="XXXXX">
                Update region1 set SManagerEmpID = #qry_getDescription2.Employeeid#
             where regionID = #holdRegionID#
           </cfquery>
       </cfif>
</cfloop>


Since you are updating the same column and the same record again and again, you are just over-writing the data in every pass of the loop.

Unless you can guaranteed that qry_getDescription2  will only return 1 record you are over writing your data





 

by: erikTsomikPosted on 2009-05-15 at 08:27:17ID: 24396818

practically it should return only 1 record

 

by: gdemariaPosted on 2009-05-15 at 08:41:50ID: 24396976

Ok, we'll see.  

Here is a cleaned version of the code.   You don't need the extra queries and loops, just one update statement.

A couple of observations:

<cfoutput query="qry_getDescription" group="OpUnit">  <---- why the group ?  

You are grouping here by opUnit, but never using the 2nd level of cfoutput to do anything with the group.  You are only using the employeeID from this query... is there only one employeeID per opUnit?  

In your query to populate the AVPEmpID, you were not including the optUNit in your where clause, I added it here because it seemed like an oversight...

    and OpUnit in ('#qry_getDescription.OpUnit#')

<cfsetting requesttimeout="9000">
<cfparam name="holdRegionID" default="0">
 
<cfquery name="qry_getDescription" datasource="xxxxx">
  Select * from OrgUnitLocation
  where  jobCode in ('8074','60851')
  order by OpUnit
</cfquery>
 
<CFQUERY name="EraseAreas"  datasource="XXXXX" >
  Delete  from Area1
</cfquery>
<CFQUERY name="EraseRegions"  datasource="XXXXXX" >
  Delete  from Region1
</cfquery>
 
<cfoutput query="qry_getDescription" group="OpUnit">
 
	<CFQUERY name="GetRegion"  datasource="XXXXX">
	  select * 
	  from Region1 r
	  where   r.ManagerEmpID = #val(qry_getDescription.EmployeeID)#
	</cfquery>
 
    <cfif GetRegion.recordcount eq 0>
         <!---insert into region Table managerEmpID--->
         <CFQUERY name="qry_insertManger"  datasource="XXXXXX">
           insert into region1 (name,ManagerEmpID) values ('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#)
         </cfquery>
         <cfquery name="GetPkey" datasource="#request.datasource#">
          select SCOPE_IDENTITY( ) as ID
         </cfquery>  
         <cfset holdRegionID = GetPkey.ID>
 
		 <CFQUERY name="qry_insertManger"  datasource="XXXXX">
		   Update region1 
		     set SManagerEmpID = (Select Employeeid from OrgUnitLocation
		         where  jobCode in ('5655','7080')
		         and OpUnit in ('#qry_getDescription.OpUnit#')
			     )
		       , AVPEmpID = (Select Employeeid from OrgUnitLocation
		         where  jobCode in ('8070','8073')
		         and OpUnit in ('#qry_getDescription.OpUnit#')
			     )
		  where regionID = #holdRegionID#
		</cfquery>
    </cfif>
                         
</cfoutput>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:

Select allOpen in new window

 

by: erikTsomikPosted on 2009-05-19 at 10:05:16ID: 24424140

This part is working OK. Now I need to add an Area piece . I was trying to do in the same manner by does not seems to work. First it insert the same regionID. Second, it execute 4 rows and then give the error

<cfsetting requesttimeout="9000">
	<cfquery name="qry_getDescription" datasource="xxxxx">
		Select * from OrgUnitLocation
		where  jobCode in ('8074','60851')
		order by OpUnit
	</cfquery>
	<cfquery name="qry_getArea" datasource="xxxxx">
		Select * from OrgUnitLocation
		where  jobCode in ('7072','8063','8066')
		order by OpUnit
	</cfquery>
	<cfset lOpUnit = ValueList(qry_getDescription.OpUnit)>
	<cfparam name="holdRegionID" default="0">
		<CFQUERY name="EraseAreas"  datasource="xxxxx" dbtype="ODBC">
				Delete  from Area1
			</cfquery>
			<CFQUERY name="EraseRegions"  datasource="xxxxx" dbtype="ODBC">
				Delete  from Region1
			</cfquery>
			<cfoutput query="qry_getDescription" group="OpUnit">
						<CFQUERY name="GetRegion"  datasource="xxxxx">
								select * 
								from Region1 r
								where 	r.ManagerEmpID = #EmployeeID#
						</cfquery>
							<cfif GetRegion.recordcount eq 0>
								<!---insert into region Table managerEmpID--->
									<CFQUERY name="qry_insertManger"  datasource="xxxxx">
										INsert into region1 (name,ManagerEmpID,code) 
										values 
										('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#,'#left(qry_getDescription.Employeeid,5)#')
									</cfquery>
										<cfquery name="GetPkey" datasource="xxxxx">
         							 select SCOPE_IDENTITY( ) as ID
        					 </cfquery>  
         						<cfset holdRegionID = GetPkey.ID>
									
											<!----**************Area spot ************--->
											<cfloop query="qry_getArea">
												<CFQUERY name="GetArea"  datasource="xxxxx">
													select * 
													from Area1 a
													where 	a.ManagerEmpID = #EmployeeID#
												</cfquery>
												<cfif GetArea.recordcount eq 0>
														<CFQUERY name="qry_insertManger4"  datasource="xxxxx">
															insert into Area1 (name,ManagerEmpID,regionID)
															values 
															(
																'#qry_getArea.Last_Name#',#qry_getArea.Employeeid#,#holdRegionID#
																
															)
														</cfquery>
												</cfif>
												<cfquery name="GetPkey2" datasource="xxxxx">
         							 		select SCOPE_IDENTITY( ) as ID
        							 </cfquery>  
         								<cfset holdAreaID = GetPkey2.ID>
												<CFQUERY name="qry_insertManger"  datasource="xxxxx">
                  			 	Update Area1 
                     		 	set SManagerEmpID = (Select top 1 Employeeid from OrgUnitLocation
                         	where  jobCode in ('7073') and OpUnit in ('#qry_getArea.OpUnit#'))
                       		, ADRCEmpID = (Select top 1 Employeeid from OrgUnitLocation
                        	 where  jobCode in ('1130') and OpUnit in ('#qry_getArea.OpUnit#'))
			                  	where AreaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdAreaID#">
               				 </cfquery>
												
											</cfloop>
											
											<!---**************End of Area SPot **************--->
										
										<!---get all SManagerID--->
											  <CFQUERY name="qry_insertManger"  datasource="xxxxx">
                  			 Update region1 
                     		 set SManagerEmpID = (Select Employeeid from OrgUnitLocation
                         where  jobCode in ('5655','7080') and OpUnit in ('#qry_getDescription.OpUnit#'))
                       , AVPEmpID = (Select Employeeid from OrgUnitLocation
                         where  jobCode in ('8070','8073') and OpUnit in ('#qry_getDescription.OpUnit#'))
			                  where regionID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdRegionID#">
                </cfquery>
									<!---if there is a record then look for the Sales manager--->
								</cfif>
			
											
				</cfoutput>
			Complete feed congratulations

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:

Select allOpen in new window

 

by: erikTsomikPosted on 2009-06-03 at 14:02:03ID: 24541320

how would i add the piece that would update the Location piece(commented out part)

<cfsetting requesttimeout="9000">
	<cfquery name="qry_getDescription" datasource="XXXXX">
		Select * from OrgUnitLocation
		where  Position = 'AVP' and PrimaryPosition = 1
		order by OpUnit
	</cfquery>
	<cfquery name="qry_getArea" datasource="XXXXX">
		Select * from OrgUnitLocation
		where  Position = 'AM' and PrimaryPosition = 1
		order by OpUnit
	</cfquery>
	
	
	<cfset lLocationID = ValueList(qry_getArea.OpUnit)>
	<cfparam name="holdRegionID" default="0">
	<cfparam name="holdAreaID" default="0">
			<CFQUERY name="eraseLocArea"  datasource="XXXXX">
				Update Location
					Set AreaID = NULL
			</cfquery>
			<CFQUERY name="EraseAreas"  datasource="XXXXX">
				Delete  from Area
			</cfquery>
			<CFQUERY name="EraseRegions"  datasource="XXXXX">
				Delete  from Region
			</cfquery>
		
		
			<cfoutput query="qry_getDescription" group="OpUnit">
						<CFQUERY name="GetRegion"  datasource="XXXXX">
								select * 
								from Region r
								where 	r.ManagerEmpID = #EmployeeID#
						</cfquery>
							<cfif GetRegion.recordcount eq 0>
								<!---insert into region Table managerEmpID--->
									<CFQUERY name="qry_insertManger"  datasource="XXXXX">
										INsert into region (name,ManagerEmpID,code) 
										values 
										('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#,'#left(qry_getDescription.Employeeid,5)#')
									</cfquery>
										<cfquery name="GetPkey" datasource="XXXXX">
         							 select SCOPE_IDENTITY( ) as ID
        					 </cfquery>  
         						<cfset holdRegionID = GetPkey.ID>
									
											<!----**************Area spot ************--->
											<cfloop query="qry_getArea">
												<CFQUERY name="GetArea"  datasource="XXXXX">
													select * 
													from Area a
													where 	a.ManagerEmpID = #EmployeeID#
												</cfquery>
												<cfif GetArea.recordcount eq 0>
														<CFQUERY name="qry_insertManger4"  datasource="XXXXX">
															insert into Area (name,ManagerEmpID,regionID)
															values 
															(
																'#qry_getArea.Last_Name#',#qry_getArea.Employeeid#,#holdRegionID#
																
															)
														</cfquery>
												</cfif>
												<cfquery name="GetPkey2" datasource="XXXXX">
         							 		select SCOPE_IDENTITY( ) as ID
        							 </cfquery>  
         								<cfset holdAreaID = GetPkey2.ID>
											
												
												
												<CFQUERY name="qry_insertManger"  datasource="XXXXX">
                  			 	Update Area 
                     		 	set SManagerEmpID = (Select top 1 Employeeid from OrgUnitLocation
                         	where  Position = 'ASM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
                       		, ADRCEmpID = (Select top 1 Employeeid from OrgUnitLocation
                        	 where  Position = 'ADRC' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
			                  	where AreaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdAreaID#">
               				 </cfquery>
												
					
												
											</cfloop>
											
											<!---**************End of Area SPot **************--->
										
										<!---get all SManagerID--->
											  <CFQUERY name="qry_insertManger"  datasource="XXXXX">
                  			 Update region1 
												 	<cfif qry_getDescription.Position eq 'VPFSM' and qry_getDescription.PrimaryPosition eq 1>
                     		 set SManagerEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position IN ('VPFSM') and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
												 <cfelse>
												 	set SManagerEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position IN ('AVPFSM') and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
												 </cfif>
                       , AVPEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position = 'SAM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
			                  where regionID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdRegionID#">
                </cfquery>
									<!---if there is a record then look for the Sales manager--->
								<!---	<CFQUERY name="qry_UpdateLocation"  datasource="XXXXX">
													Update Location set AreaID = #GetPkey2.ID# where OpUnit  = #qry_getDescription.OpUnit#
													
												</cfquery>
												The OpUnit &nbsp;#qry_getDescription.OpUnit# was Updated to #GetPkey2.ID#--->
								</cfif>
			
											
				</cfoutput>
			Complete feed congratulations

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:

Select allOpen in new window

 

by: gdemariaPosted on 2009-06-04 at 10:05:21ID: 24549063

Erik, is this the question you were writing to me about?   Is your last post the latest code update?

You are trying to figure out how to update the location as in..

   Update Location set AreaID = #GetPkey2.ID# where OpUnit  = #qry_getDescription.OpUnit#

What is your question about this?  Where is the difficulty?

 

by: erikTsomikPosted on 2009-06-04 at 10:12:25ID: 24549123

when i update the regionID in the area table it put all the same regionIDs. here is my latest code. I seems to got it to work but would you mind take a look at

<cfsetting requesttimeout="9000">
<cfparam name="holdRegionID" default="0">
	<cfquery name="qry_getDescription" datasource="XXXXX">
		Select * from OrgUnitLocation
		where  Position = 'AVP' and PrimaryPosition = 1
		order by OpUnit
	</cfquery>
	
	
	
<!---	<cfset lLocationID = ValueList(qry_getArea.OpUnit)>--->
	<cfparam name="holdRegionID" default="0">
	<cfparam name="holdAreaID" default="0">
			<CFQUERY name="eraseLocArea"  datasource="XXXXX">
				Update Location
					Set AreaID = NULL
			</cfquery>
			<CFQUERY name="EraseAreas"  datasource="XXXXX">
				Delete  from Area
			</cfquery>
			<CFQUERY name="EraseRegions"  datasource="XXXXX">
				Delete  from Region
			</cfquery>
		
		
			<cfoutput query="qry_getDescription" group="OpUnit">
						<CFQUERY name="GetRegion"  datasource="XXXXX">
								select * 
								from Region r
								where 	r.ManagerEmpID = #val(qry_getDescription.EmployeeID)#
						</cfquery>
							<cfif GetRegion.recordcount eq 0>
								
								<!---insert into region Table managerEmpID--->
									<CFQUERY name="qry_insertManger"  datasource="XXXXX">
										INsert into region (name,ManagerEmpID,code) 
										values 
										('#qry_getDescription.last_name#',#qry_getDescription.Employeeid#,'#left(qry_getDescription.Employeeid,5)#')
									</cfquery>
										<cfquery name="GetPkey" datasource="XXXXX">
         							 select SCOPE_IDENTITY( ) as ID
        					 </cfquery>  
         						<cfset holdRegionID = GetPkey.ID>
											<!---get all SManagerID--->
											  <CFQUERY name="qry_insertManger"  datasource="XXXXX">
                  			 Update region 
												 	<cfif qry_getDescription.Position eq 'VPFSM' and qry_getDescription.PrimaryPosition eq 1>
                     		 set SManagerEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position IN ('VPFSM') and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
												 <cfelse>
												 	set SManagerEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position IN ('AVPFSM') and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
												 </cfif>
                       , AVPEmpID = (Select Employeeid from OrgUnitLocation
                         where  Position = 'SAM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getDescription.OpUnit)#'))
			                  where regionID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdRegionID#">
                </cfquery>
										</cfif>
											<!----**************Area spot ************--->
										</cfoutput>
												<cfquery name="qry_getArea" datasource="XXXXX">
													Select * from OrgUnitLocation
													where  Position = 'AM' and PrimaryPosition = 1 <!---and OpUnit =  #qry_getDescription.OpUnit#--->
													order by OpUnit
											</cfquery>
											<cfloop query="qry_getArea">
												<CFQUERY name="GetArea"  datasource="XXXXX">
													select * 
													from Area a
													where 	a.ManagerEmpID = #qry_getArea.EmployeeID#
												</cfquery>
												<cfif GetArea.recordcount eq 0>
														<CFQUERY name="qry_insertManger4"  datasource="XXXXX">
															insert into Area (name,ManagerEmpID)
															values 
															(
																'#qry_getArea.Last_Name#',#qry_getArea.Employeeid#
																
															)
														</cfquery>
														<cfquery name="GetPkey2" datasource="XXXXX">
         							 		select SCOPE_IDENTITY( ) as ID
        							 </cfquery>  
         								<cfset holdAreaID = GetPkey2.ID>
												
												</cfif>
											<CFQUERY name="qry_insertManger5"  datasource="XXXXX">
                  			 	Update Area 
                     		 	set SManagerEmpID = (Select top 1 Employeeid from OrgUnitLocation
                         	where  Position = 'ASM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
                       		, ADRCEmpID = (Select top 1 Employeeid from OrgUnitLocation
                        	 where  Position = 'ADRC' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#')),
													 regionID = (Select  r.regionID from OrgUnitLocation
													 inner join Region r on r.ManagerEmpID = OrgUnitLocation.EmployeeID
                         	where  OrgUnitLocation.Position = 'AVP' and OrgUnitLocation.PrimaryPosition = 1 
													and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
			                  	where AreaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdAreaID#">
               				 </cfquery>
												<cfquery name="getLocations" datasource="XXXXX">
													Select opUnit from Location where OpUnit = '#trim(qry_getArea.OpUnit)#'
													order by OpUnit
												</cfquery>		
												<cfif getLocations.RecordCount gt 0>
													<cfquery name="qry_UpdateLocation" datasource="XXXXX">
														Update Location set AreaID = #holdAreaID# where opUnit = '#trim(qry_getArea.OpUnit)#'
													</cfquery>
												</cfif>
												
										
												</cfloop>
				
			Complete feed congratulations

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:

Select allOpen in new window

 

by: gdemariaPosted on 2009-06-04 at 10:42:38ID: 24549416

Are you referring to this update statement ?

Update Area
               set SManagerEmpID = (Select top 1 Employeeid from OrgUnitLocation
                                    where  Position = 'ASM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
                 , ADRCEmpID = (Select top 1 Employeeid from OrgUnitLocation
                                where  Position = 'ADRC' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
                   , regionID = (Select  r.regionID
                          from OrgUnitLocation
                        inner join Region r on r.ManagerEmpID = OrgUnitLocation.EmployeeID
                        where  OrgUnitLocation.Position = 'AVP' and OrgUnitLocation.PrimaryPosition = 1
                        and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
            where AreaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdAreaID#">


Here are some observations, not sure if any will help...

<cfloop query="qry_getArea">
		<CFQUERY name="GetArea" datasource="XXXXX">
			select * 
			from Area a
			where 	a.ManagerEmpID = #qry_getArea.EmployeeID#
		</cfquery>
		<cfif GetArea.recordcount eq 0>
			<CFQUERY name="qry_insertManger4" datasource="XXXXX">
				insert into Area (name,ManagerEmpID)
				values ('#qry_getArea.Last_Name#',#qry_getArea.Employeeid#)
			</cfquery>
			<cfquery name="GetPkey2" datasource="XXXXX">
				select SCOPE_IDENTITY( ) as ID
			</cfquery>
		    <cfset holdAreaID = GetPkey2.ID>
 
		</cfif>
 
**** If a record already exists in GetArea then HoldAreaID is either 0 or the value from the previous loop, it is not set.
		
		<CFQUERY name="qry_insertManger5" datasource="XXXXX">
		Update Area 
		   set SManagerEmpID = (Select top 1 Employeeid from OrgUnitLocation
		                        where  Position = 'ASM' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
		     , ADRCEmpID = (Select top 1 Employeeid from OrgUnitLocation
		                    where  Position = 'ADRC' and PrimaryPosition = 1 and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
  		     , regionID = (Select  r.regionID 
			        from OrgUnitLocation
            		inner join Region r on r.ManagerEmpID = OrgUnitLocation.EmployeeID
		            where  OrgUnitLocation.Position = 'AVP' and OrgUnitLocation.PrimaryPosition = 1 
		            and OpUnit in ('#trim(qry_getArea.OpUnit)#'))
		where AreaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#holdAreaID#">
		</cfquery>
 
 
****** Can you show what the value of #trim(qry_getArea.OpUnit)#  may be?
this seems to be the wrong syntax:  OpUnit in ('#trim(qry_getArea.OpUnit)#') 
 
Is it a string or number?  
 
Should it be a string: OpUnit = '#trim(qry_getArea.OpUnit)#'
 
or a number?    OpUnit = #val(qry_getArea.OpUnit)#

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:

Select allOpen in new window

 

by: erikTsomikPosted on 2009-06-04 at 10:45:31ID: 24549444

it is a string

 

by: gdemariaPosted on 2009-06-04 at 10:48:12ID: 24549462

Ok, so get rid of the in () clause.

what about HoldAreaID  is it ok that you don't set that if the record is not found?

 

by: erikTsomikPosted on 2009-06-04 at 11:13:17ID: 24549726

it is ok

 

by: erikTsomikPosted on 2009-06-04 at 11:30:52ID: 24549908

now the problem is the following. Some locations do not get areaID. So the same AreaManager can be in multiple locations

 

by: gdemariaPosted on 2009-06-04 at 11:57:50ID: 24550190


 Ok.....  so what's the problem?

 

by: erikTsomikPosted on 2009-06-04 at 12:29:00ID: 24550551

OK. Now my requirements has changed.
this query
      Select * from OrgUnitLocation
            where  Position = 'AVP' and PrimaryPosition = 1
            order by OpUnit

Must be changed to this
Select * from OrgUnitLocation
            where  Position in( 'AVP','VPFSM','AVPFSM','AM','ASM','ADRC','SAM') and PrimaryPosition = 1
            order by OpUnit

So will loop through the community
And then the region will be defined by combination of 3 not just by 1 AVP

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...