Ok guys, I'm really hoping one of you can pull me out on this one -- each time I think I get it solved, it rears its disgusting nasty revulting head again --
Here's the deal:
I've got a SPROC that may or may not need some extra work to its where clause depending on the current state of the webpage that is calling it -- This depends on three different things: SVP, VPO, and DM -- if any of those variables have a value in the webpage, then the SPROC must filter by that criteria in order to return what I need.
So, I declared four variables in the SPROC, @svp, @vpo, & @dm -- and the fourth, @where, will hold the extra where clause (if any) if any of those other three variables get sent a value. Here's a bit of code:
Ok, so notice that @where is initially assigned a value of '' (empty string) and if any of the other three variables get a value, then I assign a string to @where, and then I use @where like this:
SELECT @complete = COUNT(RespondentUniqueKey) FROM cscResponse2001 INNER JOIN cMasterDemo ON cscResponse2001.ourID = cMasterDemo.[id] WHERE + @where + responseDate >= '06/01/01' AND responseDate <= '06/30/01' AND method = @method AND firstMail >= @startDate AND firstMail <= @endDate AND accountType = @accountType
So that it gets inserted right into the middle of that select statement -- if it's blank, then no harm, no foul (and in fact, that's the only time it's working), but if it's not blank, then its contents are read into the select statement and translated into my desired filtered results.
Are you with me so far? Good. Now comes the trouble...
Now don't ask me why, but everything was working just fine before I added all this where crap... but now, if @where gets a value, my @startDate and @endDate start throwing this error:
-----
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
-----
and I'm assigning those two variables in an ASP page like this:
comObj.Parameters("@startDate"
= "06/01/01"
comObj.Parameters("@endDate"
= "06/30/01"
which seemed to be working OK before I tossed this where stuff into the mix -- ***sigh***
And of course, the error is thrown right when I try to:
comObj.Execute
So then, I thought, well, I'll just CAST() them into a smalldatetime once I get them into the SPROC -- no dice, though. Same error.
So basically, I'm thinking that it's something else besides the datetime hicky dick (cuz like I said, it WAS working) -- and this is the first time I've ever tried to use a variable as part of my SELECT statement inside the SPROC itself, and to be honest, I'm not even sure that such a thing is possible (Please, oh please, let it be possible) --
So there you have it.... I know it was a bit long winded, but I wanted to get it all out there and pray that one of my good Tek-Tips SQL Server gurus out there in la-la land could set me back on the straight and narrow.
Thanks for any insight. I'm up against a wall here.
:-I
Paul Prewett
Here's the deal:
I've got a SPROC that may or may not need some extra work to its where clause depending on the current state of the webpage that is calling it -- This depends on three different things: SVP, VPO, and DM -- if any of those variables have a value in the webpage, then the SPROC must filter by that criteria in order to return what I need.
So, I declared four variables in the SPROC, @svp, @vpo, & @dm -- and the fourth, @where, will hold the extra where clause (if any) if any of those other three variables get sent a value. Here's a bit of code:
Code:
@svp int = 0,
@vpo int = 0,
@dm int = 0,
@where varchar(100) = ''
-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
IF @svp <> 0
SELECT @where='(svp=' + CAST(@svp AS varchar) + ') AND '
IF @vpo <> 0
SELECT @where='(vpo=' + CAST(@vpo AS varchar) + ') AND '
IF @dm <> 0
SELECT @where='(dm=' + CAST(@dm AS varchar) + ') AND '
Ok, so notice that @where is initially assigned a value of '' (empty string) and if any of the other three variables get a value, then I assign a string to @where, and then I use @where like this:
SELECT @complete = COUNT(RespondentUniqueKey) FROM cscResponse2001 INNER JOIN cMasterDemo ON cscResponse2001.ourID = cMasterDemo.[id] WHERE + @where + responseDate >= '06/01/01' AND responseDate <= '06/30/01' AND method = @method AND firstMail >= @startDate AND firstMail <= @endDate AND accountType = @accountType
So that it gets inserted right into the middle of that select statement -- if it's blank, then no harm, no foul (and in fact, that's the only time it's working), but if it's not blank, then its contents are read into the select statement and translated into my desired filtered results.
Are you with me so far? Good. Now comes the trouble...
Now don't ask me why, but everything was working just fine before I added all this where crap... but now, if @where gets a value, my @startDate and @endDate start throwing this error:
-----
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
-----
and I'm assigning those two variables in an ASP page like this:
comObj.Parameters("@startDate"
comObj.Parameters("@endDate"
which seemed to be working OK before I tossed this where stuff into the mix -- ***sigh***
And of course, the error is thrown right when I try to:
comObj.Execute
So then, I thought, well, I'll just CAST() them into a smalldatetime once I get them into the SPROC -- no dice, though. Same error.
So basically, I'm thinking that it's something else besides the datetime hicky dick (cuz like I said, it WAS working) -- and this is the first time I've ever tried to use a variable as part of my SELECT statement inside the SPROC itself, and to be honest, I'm not even sure that such a thing is possible (Please, oh please, let it be possible) --
So there you have it.... I know it was a bit long winded, but I wanted to get it all out there and pray that one of my good Tek-Tips SQL Server gurus out there in la-la land could set me back on the straight and narrow.
Thanks for any insight. I'm up against a wall here.
:-I
Paul Prewett

