Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to update more than one records at one time

New Here ,
Apr 11, 2006 Apr 11, 2006
hello guys..
how to update a few records (more than one) with different IDs at the same time? i tried to make a query like this (see below), but only one record (more than one data in the same field)has been updated.

-----------------------------------------
<cfquery name="rec" datasource="DatKoku">
select *
from tbl_pilih
where id_pel = '#form.idpel#'
</cfquery>

<cfquery name="updtrecord" datasource="DatKoku">
update tbl_pilih
set
kptsn = '#form.suk_pil#',
trkh_kptsn = '#Dateformat(TodayDate,"dd/mm/yy")#|#TimeFormat(Now(),"hh:mm:ss tt")#'
where id_pel = '#rec.id_pel#'
</cfquery>

<cfquery name="outputrecord" datasource="DatKoku">
select *
from tbl_pilih
where id_pel = '#form.idpel#'
</cfquery>
-------------------------------------------
TOPICS
Database access
536
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2006 Apr 12, 2006
I don't see any need for the select-statements. If you wish to update just the kptsn and trkh_kptsn values corresponding to an id_pel value of '#form.idpel#', then just do

<cfquery name="updtrecord" datasource="DatKoku">
update tbl_pilih
set
kptsn = '#form.suk_pil#',
trkh_kptsn = '#Dateformat(TodayDate,"dd/mm/yy")#|#TimeFormat(Now(),"hh:mm:ss tt")#'
where id_pel = '#form.id_pel#'
</cfquery>

This query will update just one record(that is, one row). It will update the values of kptsn and trkh_kptsn whose id_pel is form.id_pel.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2006 Apr 12, 2006
If you want to do the same update to more than one record, do something like

update mytable
set this = that
where somefield in (val1, val2, val3, etc)

If you want different records to get different values, the simplest method is to run a separate query for each record.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 13, 2006 Apr 13, 2006
Dan Bracuk, i'll try 1st. Thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2006 Apr 22, 2006
it didn't work. the solution that u give me can't update the datas at the same time. anybody can help me pls..
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2006 Apr 23, 2006
LATEST
Take the query,

<cfquery name="rec" datasource="DatKoku">
select *
from tbl_pilih
where id_pel = '#form.idpel#'
</cfquery>


If every row in the table has a distinct id_pel, then what you ask is actually an impossible question. It will have no answer. Distinct IDs imply that the resultset will contain at most one distinct value of id_pel. That means, there can be at most one row that satisfies the condition, where id_pel = '#rec.id_pel#' in the update query. That in turn means the update query can update at most one row at a time.

If, however, the resultset of rec consists of multiple rows, it will mean that there are multiple rows in the table that have the same id_pel . Then, your update query, updtrecord, should update all the rows that share that value of id_pel.






Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources