Re: Problem with an insert query
Hello. The INSERT ... VALUES and INSERT ... SET forms of the statement insert rows based on explicitly specified values. So you can't use select in the value clause. Instead you should use insert ... select. By the way: don't forget to escape single quotes in text which you insert. See: http://dev.mysql.com/doc/mysql/en/INSERT_SELECT.html And good answer of Paul DuBois at: http://www.mail-archive.com/mysql@lists.mysql.com/msg26639.html GH [EMAIL PROTECTED] wrote: In my database I have the following tables: +-+ | Tables_in_AHRC | +-+ | Attendance | | Participants| | ProgressNotes | | Sessions| | Staff | | StaffAttendance | +-+ I am trying to insert data in the ProgressNotes Table using the following query but it does not work. Can someone please assist? Thank You. INSERT INTO ProgressNotes ( DateOfReport, NumPartReg, NumPartPresent, NumStaffPresent, NumVolPresent, TodaysActivities, DescribeSession, Interactions, Comments, Plans, Signed ) VALUES ( '1', Select Count(*) From Attendance WHERE Session = 1, Select Count(*) From Attendance WHERE Session = 1 AND Present = 'Yes', Select Count(*) From StaffAttendance WHERE Session = 1 AND Present = 'Yes', '0', 'Attempt to start program', 'Due to the lack of completed paperwork between and SITE, we were unable to complete the program as schedule. We informed the consumers of the situation.', 'Understandably, the consumers were upset. The Dean (SR) was kind enough to try and help explain to our members that there was a communications problem that caused the paperwork not to be completely in place before we started the program. LL and I got the members' phone numbers so that we can advise them if we are canceled next week. One consumer, DSL, was being uncooperative with us through out the time we were in session. She was pouting and having an attitude with all who were there including: the parents of another consumer, Dean SR and staff. I attempted to calm Ms. L down and stated that I was informed by MR that there might be a problem at 6:45PM on Friday. After the close of business hours on Friday. Ms. L stated on many occasions that M should of told her that we were not having class today. She called a couple of persons including a counselor at ZZZ, to which I was able to speak and explain the situation. I attempted to explain the entire situation and that we did not definitely know that they were not going to let us in to the room until today. The counselor seemed to be understanding. I told her that we are expecting to run the program next week and that we would contact Ms. L if we are told that we can not.', 'Everyone (Consumers, Parents and Staff) wishes to have the program by next week please help us get up and running.', 'Attempt to start up the program next session.', 'GMH, PgmLdr' ); mysql describe ProgressNotes; +--+--+--+-+-+---+ | Field| Type | Null | Key | Default | Extra | +--+--+--+-+-+---+ | DateOfReport | int(2) | | PRI | 0 | | | NumPartReg | int(2) | | | 0 | | | NumPartPresent | int(2) | | | 0 | | | NumStaffPresent | int(1) | | | 0 | | | NumVolPresent| int(2) | | | 0 | | | TodaysActivities | varchar(255) | | MUL | | | | DescribeSession | text | | | | | | Interactions | text | | | | | | Comments | text | | | | | | Plans| text | | | | | | Signed | text | | | | | +--+--+--+-+-+---+ 11 rows in set (0.00 sec) [QUOTE PHPMYADMIN RESULTS] Database AHRC - Table Participants running on localhost Error There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem ERROR: Unclosed quote @ 2040 STR: ' SQL: INSERT INTO ProgressNotes ( DateOfReport, NumPartReg, NumPartPresent, NumStaffPresent, NumVolPresent, TodaysActivities, DescribeSession, Interactions, Comments, Plans, Signed ) VALUES ( '1', Select Count(*) From Attendance WHERE Session = 1, Select
Re: Problem with an insert query
GH wrote: I am trying to insert data in the ProgressNotes Table using the following query but it does not work. Can someone please assist? Thank You. [snip] 'Understandably, the consumers were upset. The Dean (SR) was kind enough to try and help explain to our members that there was a communications problem that caused the paperwork not to be completely in place before we started the program. LL and I got the members' phone numbers so that we can advise them if we are canceled next week. [snip] You've got a single apostrophe after members in the text above. If you want it to insert the apostrophe, it needs to be escaped or doubled up. ...and I got the members'' phone numbers so There may be others, but that was the only one I could find. You'll probably find that the other error relating to the select count(*)... may well disappear when you fix this. Hope this helps Stephen -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Problem with an insert query
In my database I have the following tables: +-+ | Tables_in_AHRC | +-+ | Attendance | | Participants| | ProgressNotes | | Sessions| | Staff | | StaffAttendance | +-+ I am trying to insert data in the ProgressNotes Table using the following query but it does not work. Can someone please assist? Thank You. INSERT INTO ProgressNotes ( DateOfReport, NumPartReg, NumPartPresent, NumStaffPresent, NumVolPresent, TodaysActivities, DescribeSession, Interactions, Comments, Plans, Signed ) VALUES ( '1', Select Count(*) From Attendance WHERE Session = 1, Select Count(*) From Attendance WHERE Session = 1 AND Present = 'Yes', Select Count(*) From StaffAttendance WHERE Session = 1 AND Present = 'Yes', '0', 'Attempt to start program', 'Due to the lack of completed paperwork between and SITE, we were unable to complete the program as schedule. We informed the consumers of the situation.', 'Understandably, the consumers were upset. The Dean (SR) was kind enough to try and help explain to our members that there was a communications problem that caused the paperwork not to be completely in place before we started the program. LL and I got the members' phone numbers so that we can advise them if we are canceled next week. One consumer, DSL, was being uncooperative with us through out the time we were in session. She was pouting and having an attitude with all who were there including: the parents of another consumer, Dean SR and staff. I attempted to calm Ms. L down and stated that I was informed by MR that there might be a problem at 6:45PM on Friday. After the close of business hours on Friday. Ms. L stated on many occasions that M should of told her that we were not having class today. She called a couple of persons including a counselor at ZZZ, to which I was able to speak and explain the situation. I attempted to explain the entire situation and that we did not definitely know that they were not going to let us in to the room until today. The counselor seemed to be understanding. I told her that we are expecting to run the program next week and that we would contact Ms. L if we are told that we can not.', 'Everyone (Consumers, Parents and Staff) wishes to have the program by next week please help us get up and running.', 'Attempt to start up the program next session.', 'GMH, PgmLdr' ); mysql describe ProgressNotes; +--+--+--+-+-+---+ | Field| Type | Null | Key | Default | Extra | +--+--+--+-+-+---+ | DateOfReport | int(2) | | PRI | 0 | | | NumPartReg | int(2) | | | 0 | | | NumPartPresent | int(2) | | | 0 | | | NumStaffPresent | int(1) | | | 0 | | | NumVolPresent| int(2) | | | 0 | | | TodaysActivities | varchar(255) | | MUL | | | | DescribeSession | text | | | | | | Interactions | text | | | | | | Comments | text | | | | | | Plans| text | | | | | | Signed | text | | | | | +--+--+--+-+-+---+ 11 rows in set (0.00 sec) [QUOTE PHPMYADMIN RESULTS] Database AHRC - Table Participants running on localhost Error There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem ERROR: Unclosed quote @ 2040 STR: ' SQL: INSERT INTO ProgressNotes ( DateOfReport, NumPartReg, NumPartPresent, NumStaffPresent, NumVolPresent, TodaysActivities, DescribeSession, Interactions, Comments, Plans, Signed ) VALUES ( '1', Select Count(*) From Attendance WHERE Session = 1, Select Count(*) From Attendance WHERE Session = 1 AND Present = 'Yes', Select Count(*) From StaffAttendance WHERE Session = 1 AND Present = 'Yes', '0', 'Attempt to start program', 'Due to the lack of completed paperwork between and SITE, we were unable to complete the program as schedule. We informed the consumers of the situation.', 'Understandably, the consumers were upset. The Dean (SR) was kind enough to try and help explain to our members that there was a communications problem that caused the paperwork not to be completely in place before we started the program. LL and I got the members' phone numbers so that we can advise them if we