Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 12:30
Opus Opus is offline
Registered User
 
Join Date: Aug 2008
Posts: 9
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, 18:35
pierrevbaexcel pierrevbaexcel is offline
Registered User
 
Join Date: Dec 2003
Location: Ottawa, Canada
Posts: 65
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

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