HELP !!!
IGNOU MCA Students Forum


Posting in IMSF:

To Subscribe to Free SMS Alerts from IMSF, Click the Green SMS Button on the toolbar or SMS ON IMSF-IGNOU to 9870807070

  
 
Reply to this topicStart new topicStart Poll

> Help need for designing UPDATE query, In MS Access 2007
santanu
Posted: February 14, 2010 08:50 pm Posted since your last visit
Quote Post


Administrator
Group Icon

Group: Admin
Posts: 7,324
Member No.: 1
Joined: November 22, 2005

IGNOU:

MCA Joining Year: 2006
Study Centre:St. Xavier's College, Kolkata (2802)



QUOTE (Fakharuddin @ February 14, 2010 08:19 pm)
While trying to upload it has produced an error msg 'You cannot upload this type of file'. So I have changed the file extension from .accdb to .doc. Please rename the extension as .accdb.

In these cases (and also in general, in order to save server space), upload files to 4shared using the specified button below the post and then paste the 4shared link in the post.
PMEmail PosterUsers WebsiteYahooMSN
Top
IMSF
Sponsored Links Posted since your last visit


Tech for GenY


Group: Bot




IGNOU:

MCA Joining Year:
Study Centre:





Top
Fakharuddin
Posted: February 14, 2010 08:19 pm Posted since your last visit
Quote Post


Admitted
Group Icon

Group: ACTIVE Members
Posts: 58
Member No.: 6,574
Joined: June 11, 2008

IGNOU:

MCA Joining Year: 2008
Study Centre:Gauhati University Centre



Hi Friends!
I have solved this problem using VB. The codes are as below. Please check it and do comment.

CODE

Option Compare Database


Private Sub cmdtblCountMember_Click()
Dim db As Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim rCount As Long

Set db = CurrentDb()
strSQL = "SELECT mid FROM tblMember"
Set rst = db.OpenRecordset(strSQL)

'If the table has no recored
If rst.BOF = True Or rst.EOF = True Then MsgBox ("Total Record Count = 0 : Can not Update")
If rst.BOF = True Or rst.EOF = True Then Exit Sub

'Else move to the last record
rst.MoveLast

'Record count
rCount = rst.RecordCount

'Let us display msg for total record count
MsgBox ("Total Record Count = " & rCount & "")

db.Close

'Call updateCount procedure
Call updateCount

End Sub


Private Sub updateCount()
Dim db As Database
Dim rsCount As DAO.Recordset
Dim strCount As String
Dim rsUpdate As DAO.Recordset
Dim strUpdate As String
Dim str As DAO.Recordset
Dim id As Long
Dim total As Long
Dim counter As Long
Set db = CurrentDb()

counter = 0

Set str = db.OpenRecordset("SELECT mid from tblMember")
str.MoveFirst

While (str.EOF = False)
   id = str.Fields!mid

   strUpdate = ("SELECT * FROM tblCountMember WHERE mid= " & id & " ")
   Set rsUpdate = db.OpenRecordset(strUpdate)

   strCount = ("SELECT mid FROM tblMember WHERE sponsorid=  " & id & " ")
   Set rsCount = db.OpenRecordset(strCount)
       If rsCount.RecordCount = 0 Then total = 0 Else rsCount.MoveLast
       total = rsCount.RecordCount

   'Let us display msg for total count, we will off it later
   'MsgBox ("Total Member Count under sponsor ID =" & id & " is '" & total & "'")

   With rsUpdate
       .Edit
       .Fields("totalCount") = total
       .Update
   End With
   
   counter = counter + 1
   str.MoveNext
Wend

MsgBox ("Total " & counter & " Record(s) Updated")
db.Close
End Sub


I have uploaded an Access database file relating to this topic. Pl. download & check it.

MLM
PMEmail PosterUsers WebsiteYahooMSN
Top
Fakharuddin
  Posted: February 10, 2010 05:59 pm Posted since your last visit
Quote Post


Admitted
Group Icon

Group: ACTIVE Members
Posts: 58
Member No.: 6,574
Joined: June 11, 2008

IGNOU:

MCA Joining Year: 2008
Study Centre:Gauhati University Centre



You are right Santanu. I tried Chakrapani's code but it does not work. It produces an error - 'An updateable query is required'. So only VB code can help us.
PMEmail PosterUsers WebsiteYahooMSN
Top
santanu
Posted: February 09, 2010 10:12 pm Posted since your last visit
Quote Post


Administrator
Group Icon

Group: Admin
Posts: 7,324
Member No.: 1
Joined: November 22, 2005

IGNOU:

MCA Joining Year: 2006
Study Centre:St. Xavier's College, Kolkata (2802)



In MS Access, I think you have to write VBScript code for looping through records.
PMEmail PosterUsers WebsiteYahooMSN
Top
chakkrapani
Posted: February 09, 2010 07:30 pm Posted since your last visit
Quote Post


M.Tech
Group Icon

Group: Moderator
Posts: 813
Member No.: 2,569
Joined: May 09, 2007

IGNOU:

MCA Joining Year: 2007
Study Centre:CHENNAI



@Fakharuddin
The following query updates your requirement as shown in the output
(I practically did it with ORACLE)
UPDATE TBLCOUNTMEMBER A SET A.TOTALCOUNT =
(SELECT COUNT(B.MID) FROM TBLMEMBER B
WHERE A.MID = B.SPONSORID
GROUP BY B.SPONSORID)
/
10 rows updated.

SQL> SELECT * FROM TBLCOUNTMEMBER;
Hit return to continue....

       MID  SPONSORID TOTALCOUNT
---------- ---------- ----------
         0         -1          1
         1          0          3
         2          1          2
         3          1          1
         4          1          2
         5          2
         6          2
         7          3
         8          4
         9          4

10 rows selected.
PMEmail PosterYahoo
Top
Sindhu Srikant
Posted: February 09, 2010 01:14 pm Posted since your last visit
Quote Post


3rd Sem
Group Icon

Group: ACTIVE Members
Posts: 167
Member No.: 16,393
Joined: January 01, 2010

IGNOU:

MCA Joining Year: 2008
Study Centre:



The query written by santanu does the same thing provided you loop it for each mid's. This looping can be done with the help of any programming language. But as far as i know MS Access does not support such complex queries(Pl/sql) to be written directly and executed(@others, am i right? ).

In Oracle we can write Cursors to handle such requirements.
You'll learn more about Cursors in your fourth sem.

PMEmail Poster
Top
Fakharuddin
Posted: February 09, 2010 01:38 am Posted since your last visit
Quote Post


Admitted
Group Icon

Group: ACTIVE Members
Posts: 58
Member No.: 6,574
Joined: June 11, 2008

IGNOU:

MCA Joining Year: 2008
Study Centre:Gauhati University Centre



The query should update the totalCount field of tblCountMember as
midsponsoridtotalCount
0        -1   1
1        0    3
2        1    2
3        1    1
4        1    2
5        2    0
6        2    0
7        3    0
8        4    0
9        4    0


mid 1 and sponsorid 1 is the same person.  A member becomes a sponsor when he joins member under him. Member 1 is sponsor of member
2, 3 and 4. So memberCount is 3 for mid 1.
PMEmail PosterUsers WebsiteYahooMSN
Top
Sindhu Srikant
Posted: February 08, 2010 01:26 pm Posted since your last visit
Quote Post


3rd Sem
Group Icon

Group: ACTIVE Members
Posts: 167
Member No.: 16,393
Joined: January 01, 2010

IGNOU:

MCA Joining Year: 2008
Study Centre:



QUOTE (santanu @ February 05, 2010 10:19 pm)

SQL
update tblCountMember
set totalCount= (select count(sponsorid) from tblCountMember where sponsorid='1')
where mid='1'



A small change, instead of tblCountMember, tblMember can be used to take the count, if the second table is to be built dynamically containing a subset of mid's.

SQL
update tblCountMember
set totalCount= (select count(sponsorid) from tblMember where sponsorid='1')
where mid='1'

PMEmail Poster
Top
santanu
Posted: February 05, 2010 10:19 pm Posted since your last visit
Quote Post


Administrator
Group Icon

Group: Admin
Posts: 7,324
Member No.: 1
Joined: November 22, 2005

IGNOU:

MCA Joining Year: 2006
Study Centre:St. Xavier's College, Kolkata (2802)



I have doubts that the design of the table is correct. First of all, 1-to-1 relations does not have much meaning. These tables could be merged.

Are sponsorid entries the same as mid...I mean is mid being used as sponsorid too?

If so, it could be like this

SQL
update tblCountMember
set totalCount= (select count(sponsorid) from tblCountMember where sponsorid='1')
where mid='1'


Now, this will fill up the totalCount against only mid='1' and sponsorid='1'. This query has to be looped for all records, taking mid from 0..9


PMEmail PosterUsers WebsiteYahooMSN
Top
Fakharuddin
Posted: February 05, 2010 05:58 pm Posted since your last visit
Quote Post


Admitted
Group Icon

Group: ACTIVE Members
Posts: 58
Member No.: 6,574
Joined: June 11, 2008

IGNOU:

MCA Joining Year: 2008
Study Centre:Gauhati University Centre



Help need for designing UPDATE query :

--------------------------------------------------------------------------------
Hi all!

Pl. help me in designing an UPDATE query in MS Access 2007. I have 2 tables.

Table 1: tblMember(mid, sponsorid, mname)
Table 2: tblCountMember(mid, sponsorid, totalCount)

Here mid in both tables are primary and joined with 1-to-1 relationship.
Each member has a sponsor and a member becomes sponsor for other members. I want a query which will count members under each sponsor and update totalCount field in table tblCountMember with one go.

Here is an example how it will be looked after data entry.
In tbleMember -

      
midsponsoridmname
0-1OOOO
10AAAA
21BBBB
31CCCC
41DDDD
52EEEE
62FFFF
73GGGG
84HHHH
94IIII



Thanks in advance.
PMEmail PosterUsers WebsiteYahooMSN
Top

Topic Options Reply to this topic Fast ReplyStart new topicStart Poll



 



[ Script Execution time: 0.3143 ]   [ 16 queries used ]   [ GZIP Enabled ]   [ Server Load: 3.12 ]






Skin arobase par alphega@ipb-skins.org 2005 (original)

Privacy Policy