If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Need to add a parameter to sql statment

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-21-08, 11:30
Opus Opus is offline
Registered User
 
Join Date: Aug 2008
Posts: 10
Need to add a parameter to sql statment

I created the following query in MS Query (Excel 2007) and it runs without error.
--------------------------------------------------
SELECT
teachers.lastfirst,
courses.course_name,
pgfinalgrades.finalgradename,
sections.Course_Number,
sections.Section_Number,
substring(sections.expression,1,1),
substring(sections.expression,3,1),
students.lastfirst,
cast(students.Student_Number as int),
pgfinalgrades.percent,
pgfinalgrades.grade

From CC
left join pgfinalgrades on cc.studentid = pgfinalgrades.studentid
and cc.sectionid = pgfinalgrades.sectionid
and pgfinalgrades.finalgradename = 'T1'
inner join students on cc.studentid = students.id
inner join sections on cc.sectionid = sections.id
inner join courses on sections.course_number = courses.course_number
inner join teachers on sections.teacher = teachers.id

WHERE
cc.schoolid = 303
and students.enroll_status = 0
and sections.termid in (1800, 1801)

ORDER BY
teachers.lastfirst,
courses.course_name,
sections.expression,
students.lastfirst
----------------------------------------------

I'd like to have cc.schoolid (in the WHERE clause) to be a prompted parameter where the query is executed.
Reply With Quote
  #2 (permalink)  
Old 09-07-08, 17:35
pierrevbaexcel pierrevbaexcel is offline
Registered User
 
Join Date: Dec 2003
Location: Ottawa, Canada
Posts: 72
First you create a variable that will be fed by a cell

varParameter=Sheets("SoandSo").Range("A1").Value

in the SQL string you replace 303 by ccschoolid= " & varRarameter & " and students

See my post today about SQL in VBA
__________________
A piece of data is like a brick
If you don't build anything with it
It is just a brick
www.excel-examples.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On