sql server - Stored procedure called in VBA keeps going to default value for a parameter -


i have stored procedure calling excel. 1 of parameters float, , seems not getting sql server. results fine in server , when hardcode query in vba. traced in sql server profiler , it's passing in default, null aka user didn't specify. going on here?

the stored procedure:

create procedure um.topstudents     @semesterstart datetime,      @semesterend datetime,     @schoolid char(10) = null,     @gradethreshold float = null begin     select top 20          sc.schoolname school,          sd.last, sd.first, sd.ssn, sd.dob              dbo.studentrecords sr     inner join          dbo.lkpmajor mj on r.major = mj.code     inner join          dbo.tblstuddemo sd on sr.schoolid = sd.schoolid , r.ssn = sd.ssn     inner join          dbo.tblschools sc on sr.schoolid = sc.code              r.startdate between @semesterstart , @semesterend          , ((sr.schoolid = @schoolid ) or (@schoolid null))         , sr.major = '03'          , sr.program = 'scholarship'         , ((sr.grade>@gradethreshold ) or ((@gradethreshold null) , (gradethreshold >=3.0)))     order          sr.grade desc; end 

the vba:

private sub topstudents_grades_thres(semesterstart string, semesterend string, optional byval gradethreshold double)    'new adodb connection     ....     'new adodb command      'with adodb command         'use connection         'open stored procedure         .parameters.append cm_topstud.createparameter("@semesterstart", adchar, adparaminput, 8, semesterstart )         .parameters.append cm_topstud.createparameter("@semesterend ", adchar, adparaminput, 8, semesterend)         .parameters.append cm_topstud.createparameter("@gradethreshold", addouble, adparaminput, gradethreshold)         .commandtimeout = 300     end      'open command recordset      'set range & copy recordset      'close recordset & connection end sub  call topstudents_grades_thres("20150701", "20160204", 2.75) 

update: trying figure out why parameters aren't going through sql server:

create procedure [um].[usp_test]    @intparameter int = null begin     if (@intparameter null)       select 1 + 0 [test]     else       select 1 + @intparameter [test] end 

the number not going through:

private sub testsub(optional byval num integer)    ....    .parameters.append cm_numtest.createparameter("@intparameter", adinteger, adparaminput, num)    .... end sub  private sub worksheet_selectionchange(byval target range)    dim num integer    num = cint(worksheets("sheet1").range("d1"))    if activecell.address = "$a$1"     call testsub(num)    end if end sub 

your vba code sending 3 values (semesterstart, semesterend, gradethreshold) sql procedure input parameters. sql procedure expecting 4 input parameters; however, missing input parameter (schoolid) defined default null in sql procedure.

you have add ".parameters.append cm_topstud.createparameter(...)" vba schoolid, , modify [call topstudents_grades_thres("20150701", "20160204", 2.75)] [call topstudents_grades_thres("20150701", "20160204", "123456", 2.75)], assuming "123456" school id.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -