Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

recordset problem

Question posted by: =?Utf-8?B?R1ROMTcwNzc3?= (Guest) on July 21st, 2008 10:55 AM
Hi Guys, me again!!!!

I've got a little recordset problem, basically I'm trying to build a jobs by
email feature, so I have the following -

Jobs by Email table which includes -

category
location
keyword

a form where an advertiser posts their vacancy, the form submits the data to
the database and then passes the data on to the page that processes the jobs
by email query -

currently the recordset for selecting all users with matching jobs by email
notifications looks like this --

<%
Dim jbeusers__MMColParam3
jbeusers__MMColParam3 = "0"
If (Session("SITEID") <"") Then
jbeusers__MMColParam3 = Session("SITEID")
End If
%>
<%
Dim jbeusers__MMColParam
jbeusers__MMColParam = "0"
If (Session("NEWVACANCYLOCATION") <"") Then
jbeusers__MMColParam = Session("NEWVACANCYLOCATION")
End If
%>
<%
Dim jbeusers__MMColParam2
jbeusers__MMColParam2 = "0"
If (Session("NEWVACANCYCATEGORY") <"") Then
jbeusers__MMColParam2 = Session("NEWVACANCYCATEGORY")
End If
%>
<%
Dim jbeusers__MMColParam4
jbeusers__MMColParam4 = "%"
If (Session("NEWVACANCYDESCRIPTION") <"") Then
jbeusers__MMColParam4 = Session("NEWVACANCYDESCRIPTION")
End If
%>
<%
Dim jbeusers
Dim jbeusers_cmd
Dim jbeusers_numRows

Set jbeusers_cmd = Server.CreateObject ("ADODB.Command")
jbeusers_cmd.ActiveConnection = MM_recruta2_STRING
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword, JBENname FROM
dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? = JBENlocation AND ? =
JBENcategory AND JBENKeyword LIKE ?"
jbeusers_cmd.Prepared = true
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param1", 5, 1,
-1, jbeusers__MMColParam3) ' adDouble
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param2", 200,
1, 255, jbeusers__MMColParam) ' adVarChar
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param3", 200,
1, 255, jbeusers__MMColParam2) ' adVarChar
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4", 200,
1, 255, "%" + jbeusers__MMColParam4 + "%") ' adVarChar

Set jbeusers = jbeusers_cmd.Execute
jbeusers_numRows = 0
%>

this works fine if the variables are -

MMColParam3 = 31
MMColParam = Hereford
MMColParam2 = IT
MMColParam4 = dreamweaver

as I have two records in the jobs by email table that match this criteria...

However as MMColParam4 is the advert description, it would contain more than
just dreamweaverr in it, for instance when i try and use the value "we
urgently require dreamweaver developers"

The recordset returns no records...

effectively what I'm trying to do is filter records where the siteid,
location and category match of the advert and the jobs by email keyword is
contained within the description,..
Anyone got any ideas what I'm doing wrong?

Thank you

Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Bob Barrows [MVP]'s Avatar
Bob Barrows [MVP]
Guest
n/a Posts
July 21st, 2008
11:15 AM
#2

Re: recordset problem
GTN170777 wrote:
Quote:
Originally Posted by
Hi Guys, me again!!!!
>
I've got a little recordset problem, basically I'm trying to build a
jobs by email feature, so I have the following -
>
Jobs by Email table which includes -


What database are you using?
Quote:
Originally Posted by
>
category
location
keyword
>
a form where an advertiser posts their vacancy, the form submits the
data to the database and then passes the data on to the page that
processes the jobs by email query -
>
currently the recordset for selecting all users with matching jobs by
email notifications looks like this --
>

<snip>
Quote:
Originally Posted by
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword,
JBENname FROM dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? =
JBENlocation AND ? = JBENcategory AND JBENKeyword LIKE ?"

<snip>
Quote:
Originally Posted by
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4",
200, 1, ' adVarChar
>

Well, it appears that what you have done here should work ... you're going
to a little too much trouble (you could use a variant array to pass the
parameter values rather than going to the trouble of building the Parameters
collection) but that should not be causing this symptom.

Try appending the wildcards in your query rather than in the parameter
value:

If Access:
.... JBENKeyword LIKE '%' & ? & '%'"

If SQL Server:
.... JBENKeyword LIKE '%' + ? + '%'"

and change your CreateParameter call to:
255, jbeusers__MMColParam4)


************************************************** ******************************
I'm curious:
why do you write "? = JBENcategory" instead of "JBENcategory = ?"

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



=?Utf-8?B?R1ROMTcwNzc3?='s Avatar
=?Utf-8?B?R1ROMTcwNzc3?=
Guest
n/a Posts
July 21st, 2008
11:55 AM
#3

Re: recordset problem
Hi Bob,

Just tried changing that, I've put it together as an SP - shown below,

Again the recordset works fine if the description is only dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is returned --

so really what I am trying to do is select a record where the keyword is
contained in the description variuable, as well as the other criteria??

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND JBENcategory =
@category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO

Thanks for your help, any other thoughts would be great?




"Bob Barrows [MVP]" wrote:
Quote:
Originally Posted by
GTN170777 wrote:
Quote:
Originally Posted by
Hi Guys, me again!!!!

I've got a little recordset problem, basically I'm trying to build a
jobs by email feature, so I have the following -

Jobs by Email table which includes -

>
What database are you using?
>
Quote:
Originally Posted by

category
location
keyword

a form where an advertiser posts their vacancy, the form submits the
data to the database and then passes the data on to the page that
processes the jobs by email query -

currently the recordset for selecting all users with matching jobs by
email notifications looks like this --

<snip>
Quote:
Originally Posted by
jbeusers_cmd.CommandText = "SELECT JBENusername, JBENPassword,
JBENname FROM dbo.JBEmailNotification WHERE JBENsiteID = ? AND ? =
JBENlocation AND ? = JBENcategory AND JBENKeyword LIKE ?"

<snip>
Quote:
Originally Posted by
jbeusers_cmd.Parameters.Append jbeusers_cmd.CreateParameter("param4",
200, 1, ' adVarChar

Well, it appears that what you have done here should work ... you're going
to a little too much trouble (you could use a variant array to pass the
parameter values rather than going to the trouble of building the Parameters
collection) but that should not be causing this symptom.
>
Try appending the wildcards in your query rather than in the parameter
value:
>
If Access:
.... JBENKeyword LIKE '%' & ? & '%'"
>
If SQL Server:
.... JBENKeyword LIKE '%' + ? + '%'"
>
and change your CreateParameter call to:
255, jbeusers__MMColParam4)
>
>
************************************************** ******************************
I'm curious:
why do you write "? = JBENcategory" instead of "JBENcategory = ?"
>
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
>
>
>


Bob Barrows [MVP]'s Avatar
Bob Barrows [MVP]
Guest
n/a Posts
July 21st, 2008
12:05 PM
#4

Re: recordset problem
GTN170777 wrote:
Quote:
Originally Posted by
Hi Bob,
>
Just tried changing that, I've put it together as an SP - shown below,
>
Again the recordset works fine if the description is only
dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is
returned --
>
so really what I am trying to do is select a record where the keyword
is contained in the description variuable, as well as the other
criteria??
>
CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO
>


So this is SQL Server ... what version?
When you run this procedure in Query Analyzer or SSMS, does it return the
correct results? If so, the problem is in the vbscript code.

If not, you need to show me how to reproduce the symptoms. Generate a CREATE
TABLE script for your JBEmailNotification table, create some insert
statements to insert some sample data that I can run, and I will try to
repro this.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



=?Utf-8?B?R1ROMTcwNzc3?='s Avatar
=?Utf-8?B?R1ROMTcwNzc3?=
Guest
n/a Posts
July 21st, 2008
12:45 PM
#5

Re: recordset problem
Hi Bob,

MS SQL Server 2000,

the DDL for the JBEmailNotification table is

CREATE TABLE [dbo].[JBEmailNotification] (
[JBENotificationID] int IDENTITY(1, 1) NOT NULL,
[JBENsiteID] int NULL,
[JBENlocation] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENcategory] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENname] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENusername] nvarchar(225) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENcandidateID] int NULL,
[JBENPassword] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[JBENDateRegistered] datetime CONSTRAINT [DF__JBEmailNo__JBEND__3FD07829]
DEFAULT convert(char(19),getdate(),120) NULL,
[JBENKeyword] nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [aaaaaJBEmailNotification_PK] PRIMARY KEY NONCLUSTERED
([JBENotificationID])
)
ON [PRIMARY]
GO

Not to sure how to write an insert statement, currently though i just have
one record -

JBENsiteID - 31
JBENlocation = Hereford
JBENcategory = IT
JBENname = Gareth
JBENusername = Join Bytes!
JBENPassword = lorgar
JBENKeyword = dreamweaver

Hope this is of use and you can highlight what I'm doing wrong?

Thanks


"Bob Barrows [MVP]" wrote:
Quote:
Originally Posted by
GTN170777 wrote:
Quote:
Originally Posted by
Hi Bob,

Just tried changing that, I've put it together as an SP - shown below,

Again the recordset works fine if the description is only
dreamweaver, but
if it is for example, we need dreamweaver developers, nothing is
returned --

so really what I am trying to do is select a record where the keyword
is contained in the description variuable, as well as the other
criteria??

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND JBENKeyword LIKE '%'+'@Description'+'%'
GO

>
So this is SQL Server ... what version?
When you run this procedure in Query Analyzer or SSMS, does it return the
correct results? If so, the problem is in the vbscript code.
>
If not, you need to show me how to reproduce the symptoms. Generate a CREATE
TABLE script for your JBEmailNotification table, create some insert
statements to insert some sample data that I can run, and I will try to
repro this.
>
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
>
>
>


Bob Barrows [MVP]'s Avatar
Bob Barrows [MVP]
Guest
n/a Posts
July 21st, 2008
01:25 PM
#6

Re: recordset problem
GTN170777 wrote:
Quote:
Originally Posted by
Hi Bob,
>
MS SQL Server 2000,
>
the DDL for the JBEmailNotification table is
>
CREATE TABLE [dbo].[JBEmailNotification] (
[JBENotificationID] int IDENTITY(1, 1) NOT NULL,
[JBENsiteID] int NULL,
[JBENlocation] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL, [JBENcategory] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENname] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENusername] nvarchar(225)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JBENcandidateID] int
NULL, [JBENPassword] nvarchar(50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL, [JBENDateRegistered] datetime
CONSTRAINT [DF__JBEmailNo__JBEND__3FD07829] DEFAULT
convert(char(19),getdate(),120) NULL, [JBENKeyword] nvarchar(100)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT
[aaaaaJBEmailNotification_PK] PRIMARY KEY NONCLUSTERED
([JBENotificationID]) )
ON [PRIMARY]
GO
>
Not to sure how to write an insert statement,


For future reference:
INsert tablename (columns)
VALUES (<list of hard-coded values>)

There are tools to enable these statements to be generated, including this
code from Vyas:
http://vyaskn.tripod.com/code.htm#inserts

Quote:
Originally Posted by
currently though i just
have one record -
>
JBENsiteID - 31
JBENlocation = Hereford
JBENcategory = IT
JBENname = Gareth
JBENusername = Join Bytes!
JBENPassword = lorgar
JBENKeyword = dreamweaver


I just spotted your problem: you enclosed the @description parameter in
quotes:
AND JBENKeyword LIKE '%'+'@Description'+'%'

'@description' does not exist in your data, correct? it should of course be
AND JBENKeyword LIKE '%'+@Description+'%'

UPDATE dbo.JBEmailNotification
SET JBENKeyword = 'dreamweaver'
exec TEST 31,'dreamweaver','Hereford','IT'
UPDATE dbo.JBEmailNotification
SET JBENKeyword = 'dreamweaver engineer'
exec TEST 31,'dreamweaver','Hereford','IT'

The above script returns the correct results for me.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



=?Utf-8?B?T2xkIFBlZGFudA==?='s Avatar
=?Utf-8?B?T2xkIFBlZGFudA==?=
Guest
n/a Posts
July 21st, 2008
10:05 PM
#7

Re: recordset problem
I don't think Bob Barrows has completely diagnosed your problem.

He is patently correct about getting rid of the '...' around '@description',
but I think that's just part of the problem.

Let's consider what happens when you use
WHERE ...JBENKeyword LIKE '%'+@Description+'%'
and then pass in an @Description value such as
'we need dreamweaver developers'

Okay, so AFTER the substitution, you will be doing
WHERE ...JBENKeyword LIKE '%we need dreamweaver developers%'

And if you have *ONLY* the one record with the value
JBENKeyword = 'dreamweaver'
then you are essentially trying to do
WHERE ...'dreamweaver' LIKE '%we need dreamweaver developers%'

Guess what? You ain't never gonna find no match on that!!!!

*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'

You see it?

If not, look here:
http://msdn.microsoft.com/en-us/lib...32(SQL.80).aspx






=?Utf-8?B?T2xkIFBlZGFudA==?='s Avatar
=?Utf-8?B?T2xkIFBlZGFudA==?=
Guest
n/a Posts
July 21st, 2008
10:15 PM
#8

Re: recordset problem
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'

Remember. the '%' character when used with LIKE means "and any number of
other characters". So '%Dreamweaver%' means '[any
stuff]Dreamwearver[anystuff]'.

Caution: This still isn't going to find a description such as
'we need dream weaver developers'
(note the space between 'dream' and 'weaver')

Since you are using SQL Server, perhaps you would want to consider full text
searching, and then allowing your job postings to have nice long keyword
strings with every possibly fun matching keyword in them?



=?Utf-8?B?R1ROMTcwNzc3?='s Avatar
=?Utf-8?B?R1ROMTcwNzc3?=
Guest
n/a Posts
July 22nd, 2008
01:05 PM
#9

Re: recordset problem
Hi Both, Thanks for your help so far, I am sadly still having major problems
and can't get it to return any records now...

I've tried the below but get nothing

CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND JBENcategory =
@category AND @Description LIKE '%+JBENKeyword%'

When i tried @Description LIKE '%'+JBENKeyword'%' I got a Incorrect syntax
near '%'. error message

??

"Old Pedant" wrote:
Quote:
Originally Posted by
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'
>
Remember. the '%' character when used with LIKE means "and any number of
other characters". So '%Dreamweaver%' means '[any
stuff]Dreamwearver[anystuff]'.
>
Caution: This still isn't going to find a description such as
'we need dream weaver developers'
(note the space between 'dream' and 'weaver')
>
Since you are using SQL Server, perhaps you would want to consider full text
searching, and then allowing your job postings to have nice long keyword
strings with every possibly fun matching keyword in them?
>
>


Bob Barrows [MVP]'s Avatar
Bob Barrows [MVP]
Guest
n/a Posts
July 22nd, 2008
02:35 PM
#10

Re: recordset problem
GTN170777 wrote:
Quote:
Originally Posted by
Hi Both, Thanks for your help so far, I am sadly still having major
problems and can't get it to return any records now...
>
I've tried the below but get nothing
>
CREATE PROCEDURE TEST
@SiteID int,
@Description nvarchar(1000),
@location nvarchar(50),
@category nvarchar(50)
AS
SELECT JBENUsername, JBENname, JBENPassword
FROM JBEmailNotification
WHERE JBENsiteID = @SiteID AND JBENlocation = @location AND
JBENcategory = @category AND @Description LIKE '%+JBENKeyword%'
>
When i tried @Description LIKE '%'+JBENKeyword'%' I got a Incorrect
syntax near '%'. error message
>

That's because it should have said this:

@Description LIKE '%' & JBENKeyword & '%'
(I tend to use & for concatenation to avoid unexpected results)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



=?Utf-8?B?T2xkIFBlZGFudA==?='s Avatar
=?Utf-8?B?T2xkIFBlZGFudA==?=
Guest
n/a Posts
July 22nd, 2008
04:55 PM
#11

Re: recordset problem
"Bob Barrows [MVP]" wrote:
Quote:
Originally Posted by
That's because it should have said this:
>
@Description LIKE '%' & JBENKeyword & '%'
(I tend to use & for concatenation to avoid unexpected results)


Well, yes, you SHOULD use & for concatenation in VBScript and VB and even
Access SQL.

BUT *NEVER NEVER* in SQL Server! GTN even said so.

For SQL Server, look here:
http://msdn.microsoft.com/en-us/lib...46(SQL.80).aspx

The & operator in T-SQL is *ONLY* used to mean bit-wise anding.

You *MUST* use + for string concatenation in T-SQL. Period.



And this *IS* SQL Server 2000.

And

=?Utf-8?B?T2xkIFBlZGFudA==?='s Avatar
=?Utf-8?B?T2xkIFBlZGFudA==?=
Guest
n/a Posts
July 22nd, 2008
05:05 PM
#12

Re: recordset problem
*I* wrote:
Quote:
Originally Posted by
*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'


*YOU* coded
Quote:
Originally Posted by
... AND @Description LIKE '%+JBENKeyword%'


Those two are not even *CLOSE* to this same thing.

Yes, the second time I posted I typoed and left out the + operator when I
wrote
Quote:
Originally Posted by
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'


Clearly that should have been
Quote:
Originally Posted by
WHERE ... @Description LIKE '%' + JBENKeyword + '%'


We are trying to BUILD UP a string that has the keyword in the middle and a
% character on each end. And the only good way to do that in SQL Server
(T-SQL, same thing) is to use the + operator.



=?Utf-8?B?R1ROMTcwNzc3?='s Avatar
=?Utf-8?B?R1ROMTcwNzc3?=
Guest
n/a Posts
July 24th, 2008
10:45 AM
#13

Re: recordset problem
Thanks Old Pedant, works a treat (sorry for the late responce - had a cold)
I'm hoping to get on an MS SQL course, am UK based, can you recommend any?

Again thanks for your help

GTN

"Old Pedant" wrote:
Quote:
Originally Posted by
*I* wrote:
>
Quote:
Originally Posted by
*NOW* try doing
WHERE ...'we need dreamweaver developers' LIKE '%' + JBENKeyword + '%'

>
*YOU* coded
Quote:
Originally Posted by
... AND @Description LIKE '%+JBENKeyword%'

>
Those two are not even *CLOSE* to this same thing.
>
Yes, the second time I posted I typoed and left out the + operator when I
wrote
>
Quote:
Originally Posted by
So if it's not obvious, you should be doing
WHERE ... @Description LIKE '%' + JBENKeyword '%'

>
Clearly that should have been
>
Quote:
Originally Posted by
WHERE ... @Description LIKE '%' + JBENKeyword + '%'

>
We are trying to BUILD UP a string that has the keyword in the middle and a
% character on each end. And the only good way to do that in SQL Server
(T-SQL, same thing) is to use the + operator.
>
>


 
Not the answer you were looking for? Post your question . . .
184,182 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors