You have the wrong syntax.  You need

  SELECT @CourseId:= CourseId FROM Course WHERE CourseId='ENGL';

See the manual <http://dev.mysql.com/doc/mysql/en/Variables.html> for more.

Michael

Boyd E. Hemphill wrote:

I would like to do something like this in the mysql client

Select CourseId
Into @CourseId
From Course
Where CourseCd='ENGL';

I also tried @CourseId = select CourseId from Course where CourseCd = 'ENGL';


Neither syntax works. So I am wondering if there is a way to assign values using SQL in the mysql client. This would be _very_ handy for scripting.

Here is what I produced to get around the problem.  It is a bit
convoluted but if you are wishing for this functionality (and it does
not yet exist) it will do the trick:

insert into Course values(null, 21, 14, '', 99, 'Not Assigned', 0, 0)
;
select concat( 'set sql_auto_is_null = 1; ',
'set @CourseId = ', CourseId,'; ',
'update Test set CourseId = @UniCourseId where Title like
\'SAT%\'; '
)
into outfile 'update_test.sql'
from Course
where CourseId is null
;
source /var/lib/mysql/db_name/update_unitest.sql
;
set sql_auto_is_null = 0
;


Be sure to clean up your data directory by deleting the file created as
select ... into outfile places files into the diretory of the db on
which the query is entered

Boyd E. Hemphill






--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to