Listbox cfloop two different tables
What i'm trying to do is this:
On my edit page I have a listbox that needs to be pre-filled
with people already selected. But here is my problem - I have one
table named "people" and another named "records". Now the "people"
table have their permissions in it, and the records table has a
field that list the people (ie. susie,lisa,jason) that were
selected. So, my list box needs to hit the "peoples" table to pull
everyone that has the correct permissions (in case they need to add
someone) AND the records table so that I can retrieve who was
previously entered. Right now my code looks like this:
<cfquery name="qry_people">
select *
from people
where permissions = 3
</cfquery>
<cfquery name="qry_support_people">
select support_people
from reocords
where id = #id#
</cfquery>
<select name="support_people" multiple>
<cfloop query="qry_people">
<cfloop list="#qry_support_people#" index="i">
<option value="<cfoutput>#people#</cfoutput>"
<cfif #people# IS
i>selected</cfif>><cfoutput>#people#</cfoutput></option>
</cfloop>
</cfloop>
</select>
Right now this ALMOST works - it grabs everyone from the
"people" table AND it even highlights the ones that are
pre-selected from the "records" table.... BUT each name appears
TWICE.....Why? I've tried changing the one cfloop to cfoutput, but
then I don't get the whole list of names. Any help would be great -
THANKS!
<select name="support_people" multiple>
<cfoutput query="qry_people">
<cfif listfind(qry_support_people.support_people,
qry_people.people)>
<option value="#qry_people.people#"
selected>#qry_people.people#</option>
<cfese>
<option value="#qry_people.people#"
>#qry_people.people#</option>
</cfif>
</cfoutput>
</select>
but, really, do yourself a favour and normalize your db...
with table
setup like yours you are bound to hit many problems, if not
right now
then later...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Similar Messages
-
How to create a foreign key for the table from two different tables?
Hi All,
I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
code 1:
CREATE TABLE SAMPLE_CONS_CHECK
(NAME VARCHAR2(10),
SERIES VARCHAR2(5)
CREATE TABLE SAMPLE_CONS2_CHECK
(NAME VARCHAR2(5),
MODEL NUMBER
CREATE TABLE SAMPLE_CONS3_CHECK
(NAME VARCHAR2(5),
MODEL_NO NUMBER
)code 2
alter table SAMPLE_CONS_CHECK
add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS2_CHECK
add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS3_CHECK
add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS_CHECK
NAME
) ON DELETE CASCADE;
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS2_CHECK
NAME
) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
How can i solve this problem? Can anyone halp me about this?
Thanks
Edited by: orasuriya on Aug 8, 2009 2:02 AMActually the design is completely incorrect.
What you say is
I have
'foo', 'foo series'
'foo','foo model'
'foo',666
By virtue of table3 referring to both table1 and table2.
This means you actually need to have 1 (one) table:
'foo','foo series','foo model', 666
And the 'problem' disappears.
Sybrand Bakker
Senior Oracle DBA -
How to load data from a flat file to two different tables at a time.
I am not aware of Sql Loader so Please any body suggest me that is there any way to load data from excel sheet to two different tables at a time its very urgent.
with regards,
Srinivas.RRead Utilities Guide from the Oracle Documentation Library. See
<br>
Oracle Database FAQs
</br> -
How can I combine post to two different tables with one form?
I am trying to create a "phantom" record in a table to be used later in a report. How can I create a form and properly $_POST to two different tables? Thanks for any suggestions!
In POST processing, just do the insert to one table, followed by the insert to the second table. I don't understand where you are getting stuck.
Sometimes when we do an insert, we need the auto-generated ID from the newly created record as a "foreign key" for the record created in the second insert. MySQL has a nifty solution for that. The specific code depends on whether you are using the mysql, mysqli or PDO database connection. -
Selecting data from two different tables.
Do we need to use join two tables with primary/foreign key while trying to use select statement for getting data from those to table.? If no who can i go about do it.
872959 wrote:
If i am using From clause to get data from two different tables, is it necessary that both tables have column of identical data in them.In general, they ought to (or you need to join in a third table that tells you how to map rows from one table to rows of the other table).
It is not strictly necessary that there be any join condition between tables. If you don't provide a join condition, Oracle has to do a Cartesian product. That means that if there are n rows in one table and m rows in the other, the result set will have n * m rows. It is very rarely a good idea to write queries that do Cartesian products but it does occasionally happen.
Justin -
To find Common data in 2 columns in two different tables.
Hi,
Could someone help me out with a querry to find out common data from 2 columns in two different tables??
Thanks
Rajesh966915 wrote:
suppose i hav 2 tables
Table A
s.No name EID
1 aaa 123
2 bbb 234 ... etc..
and Table B
S.no salary eid location
1 mmm$ 123 india
2 ddd$ 556 Uk
3 fff$ 236 US
How do i select the common entry in both the tables??why do you post in forum for SQL & PL/SQL; yet never post anything in either language?
what do you mean by "common enrty"?
does every column value must match exactly across 2 rows in different table? -
How to compare the contents of two different tables
hello. can somebody give me an idean on how to compare the contents of two different tables in mysql?
example, i have a table named Main List and a table named New List.
The contents of the New List should be compared to the contents of the
Main List, to check if they are equal. I don't have any idea how to manipulate
this data. Hoping for your help. Thanks.it is better to comapre it using java.. try get the resultset first and store that in collections then comapre the two collections
-
Comparing row values in two different tables
Hello,
Does anyone know if it is possible to compare (and possibly highlight - which I know can be done) row values in two different tables?
I have a ZIP Code column in table A that I want to compare to a ZIP Code column in table B and highlight those ZIP Codes that are present in table B but not in table A etc. Is this possible?
Thanks,
KennethTo be able to apply conditional formatting, I must edit the formulas this way.
=IF(ISBLANK(B)," ",IF(ISERROR(VLOOKUP(B,Tableau 2 :: B,1,0))," ",VLOOKUP(B,Tableau 2 :: B,1,0)))
=IF(ISBLANK(B)," ",IF(ISERROR(VLOOKUP(B,Tableau 1 :: B,1,0))," ",VLOOKUP(B,Tableau 1 :: B,1,0)))
I replaces the four empty strings by strings containing one space character.
In the field supposed to contain the text which is not contained I just entered a single space character.
Yvan KOENIG (from FRANCE vendredi 12 septembre 2008 20:52:11) -
Extracting unique records from two different tables record
Hello,
In the following code of two different tables www.testing.com exists in both tables. I want to compare two different columns of the two different tables to get unique records.
SQL> select unique(videoLinks) from saVideos where sa_id=21;
VIDEOLINKS
www.testing.com
SQL> ed
Wrote file afiedt.buf
1* select unique(picLinks) from saImages where sa_id=21
SQL> /
PICLINKS
test
test14
www.hello.com
www.testing.comThanks & best regardsUnfortunatly you didn't mention the expected output. I guess it would be the one line
"www.testing.com"
in that case simply join the two tables.
select *
from saVideos v
join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
where v.sa_id=21;If needed then you could change the select list to retrieve only distinct values.
select unique v.sa_id, v.videolinks
from saVideos v
join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
where v.sa_id=21;I usually avoid distinct/unique whereever possible. This requires the database to do a sort and makes the query slow.
Edited by: Sven W. on Feb 10, 2011 1:55 PM -
Update two different tables by a single sql query:
Hi All,
i need to update two different talbes in a single sql query..
i m using the following query
UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
AND
UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
i m getting the following error:
Odbc driver returned an error (SQLExecDirectW).
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
but when i m ushin the same query in Microsoft SQL Server it executes properly:
please help me out...Duplicate thread. I've already answered on your other thread...
update two different tables by a single sql query: -
Insert same record on two different tables (no master detail)
Hi all,
I'd like to know how to insert 1 record into two different
tables.
the first table is corni_dati the second is cornidati_prev
anytime someone inserts a new record both tables should be
filled.
if ((isset($HTTP_POST_VARS["MM_insert"])) &&
($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO corni_dati (corni_id,
disciplina,
codice_modulo, insegnanti, classi, obiettivi, prerequisiti,
ud1, ud2,
ud3, ud4, ud5, ud6, metodologia, collegamenti, verifiche,
verifiche_note, durata, periodo_inizio, periodo_fine, note,
indirizzo,
modnum, modulo_titolo, `data`, compilato, descrizione) VALUES
(%s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s,
%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['corni_id'],
"int"),
GetSQLValueString($HTTP_POST_VARS['disciplina'],
"text"),
GetSQLValueString($HTTP_POST_VARS['codice_modulo'], "text"),
GetSQLValueString($HTTP_POST_VARS['insegnanti'],
"text"),
GetSQLValueString($HTTP_POST_VARS['classi'],
"text"),
GetSQLValueString($HTTP_POST_VARS['obiettivi'],
"text"),
GetSQLValueString($HTTP_POST_VARS['prerequisiti'], "text"),
GetSQLValueString($HTTP_POST_VARS['ud1'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud2'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud3'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud4'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud5'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud6'],
"text"),
GetSQLValueString($HTTP_POST_VARS['metodologia'], "text"),
GetSQLValueString($HTTP_POST_VARS['collegamenti'], "text"),
GetSQLValueString($HTTP_POST_VARS['verifiche'],
"text"),
GetSQLValueString($HTTP_POST_VARS['verifiche_note'], "text"),
GetSQLValueString($HTTP_POST_VARS['durata'],
"int"),
GetSQLValueString($HTTP_POST_VARS['periodo_inizio'], "text"),
GetSQLValueString($HTTP_POST_VARS['periodo_fine'], "text"),
GetSQLValueString($HTTP_POST_VARS['note'],
"text"),
GetSQLValueString($HTTP_POST_VARS['indirizzo'],
"text"),
GetSQLValueString($HTTP_POST_VARS['modnum'],
"text"),
GetSQLValueString($HTTP_POST_VARS['modulo_titolo'], "text"),
GetSQLValueString($HTTP_POST_VARS['data'],
"date"),
GetSQLValueString($HTTP_POST_VARS['compilato'],
"text"),
GetSQLValueString($HTTP_POST_VARS['descrizione'], "text"));
mysql_select_db($database_itiscorni, $itiscorni);
$Result1 = mysql_query($insertSQL, $itiscorni) or
die(mysql_error());
$insertGoTo = "creacodice_doc.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));If you are doing this then you really should have a look at
your database
design. Read up on the first 3 normal forms.
Pat.
"darrel" <[email protected]> wrote in message
news:ee77jg$302$[email protected]..
>
>
> --
>> Hi all,
>> I'd like to know how to insert 1 record into two
different tables.
>
> In your SQL query, just use two inserts:
>
> INSERT into TABLE1...; INSERT into TABLE2...
>
> Darrel
> -
Sum two different columns from two different tables
Can you select and sum two different columns, from two different tables in the same sql statement?
i.e.
table1
Item----OnHand_Qty
A--------10
A--------15
B--------10
B--------10
C--------20
table2
Item----Trx_Qty
A--------2
A--------4
A--------6
B--------1
B--------1
C--------4
I'm looking for the following results from a query
Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
A--------25Like this?
SQL> create table table1 (item,onhand_qty)
2 as
3 select 'A', 10 from dual union all
4 select 'A', 15 from dual union all
5 select 'B', 10 from dual union all
6 select 'B', 10 from dual union all
7 select 'C', 20 from dual union all
8 select 'D', 30 from dual
9 /
Tabel is aangemaakt.
SQL> create table table2 (item, trx_qty)
2 as
3 select 'A', 2 from dual union all
4 select 'A', 4 from dual union all
5 select 'A', 6 from dual union all
6 select 'B', 1 from dual union all
7 select 'B', 1 from dual union all
8 select 'C', 4 from dual union all
9 select 'E', 3 from dual
10 /
Tabel is aangemaakt.
SQL> select nvl(t1.item,t2.item) item
2 , t1.sum_onhand_qty
3 , t2.sum_trx_qty
4 from ( select item, sum(onhand_qty) sum_onhand_qty
5 from table1
6 group by item
7 ) t1
8 full outer join
9 ( select item, sum(trx_qty) sum_trx_qty
10 from table2
11 group by item
12 ) t2
13 on (t1.item = t2.item)
14 /
I SUM_ONHAND_QTY SUM_TRX_QTY
A 25 12
B 20 2
C 20 4
E 3
D 30
5 rijen zijn geselecteerd.Regards,
Rob. -
Query from two different tables
Hi All
I am having two different tables A and B. I want to select all rows containing the names like the rows in B.
I have tried the below and it does not work:
select * from A where name like (select '%'||name||'%' from B).
Can anyone help please.
Thanks
AmitHi Jeneesh
Thanks for the quick reply.
What i want is query to bring back all the name containing the string which is to be found in the table B.
Table A's content
Amit
Amita
Anjoo
Table B's Content
Ami
Query should return
Amit
Amita -
How to update two different tables by ony one sql query???
Hi All,
i need to update two different talbes in a single sql query..
i m using the following query
UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
AND
UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
i m getting the following error:
Odbc driver returned an error (SQLExecDirectW).
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
but when i m ushin the same query in Microsoft SQL Server it executes properly:
please help me out...There's no valid syntax for this, but there are some tricks you could do to achieve it.
i) You could place an update trigger on TABLE1 to update TABLE2 automatically.
ii) You could define a view across both tables and add an INSTEAD OF UPDATE trigger to it to maintain them.
If I had to do this I'd choose option2, but frankly I'd just be running two updates if it really was me. -
Hi Experts,
I have on stored procedure which returns mote than one resultset i want that to store in two different temp table how can achieve this in SQL server.
following is the stored procedure and table that i need to create.
create procedure GetData as begin select * from Empselect * from Deptend
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
exec GetData
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
exec GetData
Niraj SevalkarYou cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
create procedure GetData as
begin
select 'resultset1' as Cat,*,.. N columns from Emp
union all
select 'resultset2' as Cat,*,.. N columns from Dept
end
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
Select column1,column2,column3
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset1'
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
Select column1,column2,column3, column4
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset2'
also see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Maybe you are looking for
-
ImgBurn would like to know the manufacturer for my ts-l633n. I've looked all over the boards, and the internet and couldn't find a manufacturer. Big, big, big help needed. Thanks in advance, Amrinder This question was solved. View Solution.
-
Oracle SQL Developer Cannot Cancel Queries Properly
This was a problem with version 2 and continues to be an issue with version 3. If I chose to cancel a query that is taking a long time to run it gives me the prompt and displays that the query was cancelled. However, the query is not actually cancell
-
Hi everybody in the fourm, anyone knows which exception would thorw this? MAny thanks in advance: try { amount = Float.valueOf(text.getText()); } catch(????){ JOptionPane.showMessageDialog(frame,
-
Sorry this may be basic but I have several email accounts set up in my iphone. All are able to display email headers in the message list and are updated without a problem. However, when I tap on the selected email, the actual message is not visible.
-
Hi everyone, I have to make my green shape look exactly like the one on the right. I've got the right colors but I am not able to move the radial gradient over to the left. When I click on the gradient tool, I get a circle symobl with a line through