PC Review


Reply
Thread Tools Rate Thread

retrieve data using LIKE statement

 
 
=?Utf-8?B?aGFyc2hhIG1vZ2FsaWd1bmRsYQ==?=
Guest
Posts: n/a
 
      18th Mar 2004
Dear All
I am using ASP to retrieve data from a SQL Server database, some of the columns of the database have entries seperated by "/" for eg the entries can be ( CAR,CAR/BIKE, CAR/BIKE/VAN etc). the current system is set up to query the comlpete phrase and not individual items, for eg if there are 100 only Car items and 100 CAR/BIKE items , a search for CAR would only show the exclusive CAR items and not the ones which have CAr as well as BIKE, to over come this problem i used the LIKE statement instead of the "=" and i get the following error

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'LCL

the code for the module is given below

function createWhereClauseFromDictionary(search_fields, table_name
dim tmp_str, i, col_index, db_field_val,strReplac
tmp_str = "
for i = 1 to num_of_field
if search_fields("and_flag_" & i) = "1" the
db_field_val = "
col_index = cInt(search_fields("search_fld_" & i)
if Application(table_name)(col_index, 1) = "50" then 'bi
if uCase(search_fields("val_start_" & i)) = "TRUE" or search_fields("val_start_" & i) = "1" the
db_field_val =
elseif uCase(search_fields("val_start_" & i)) = "FALSE" or search_fields("val_start_" & i) = "0" the
db_field_val =
end i

els
db_field_val = search_fields("val_start_" & i
end i

tmp_str = tmp_str & " and " & search_fields("val_not_" & i) & "("
if len(db_field_val) > 0 then
tmp_str = tmp_str & Application(table_name)(col_index, 0
if len(search_fields("val_fin_" & i)) > 0 then 'its a rang
tmp_str = tmp_str & " >= '" & Replace(db_field_val, "'", "''") & "'
tmp_str = tmp_str & " and " & Application(table_name)(col_index, 0) & " <= '" & Replace(search_fields("val_fin_" & i), "'", "''") & "'
els
strReplace = Replace(db_field_val, "'", "''"
strReplace = Trim(strReplace

####################this is where the problem occurs###################

tmp_str = tmp_str & "LIKE '" & strReplace &"'
##############################################################
end i
els
tmp_str = tmp_str & Application(table_name)(col_index, 0) & " is null
end i
tmp_str = tmp_str & ")
end i
nex
createWhereClauseFromDictionary = tmp_st
end functio
%

I would really appreciate it if someone could help me out

thank yo
harsha
 
Reply With Quote
 
 
 
 
Norman Yuan
Guest
Posts: n/a
 
      18th Mar 2004
Ii is hard for you to debug the so complicated string processing function,
it is even harder for some else to debug it.

I'd suggest you to add following ASP code somewhere in the *.asp file to
show exactly then WHERE clause look like before you send the SQL statement
to SQL Server:

<P><%=createWhereClauseFromDictionary(fields,tblName)%></P>

Now, you may be able to verify whether the WHERE clause is correct or not
easily. You probably want to test this function with different parameter
values passed to make sure you ALWAYS get correct WHERE clause.

"harsha mogaligundla" <(E-Mail Removed)> wrote in message
news:006F2FC7-4CFB-46F6-85AD-(E-Mail Removed)...
> Dear All,
> I am using ASP to retrieve data from a SQL Server database,

some of the columns of the database have entries seperated by "/" for eg
the entries can be ( CAR,CAR/BIKE, CAR/BIKE/VAN etc). the current system is
set up to query the comlpete phrase and not individual items, for eg if
there are 100 only Car items and 100 CAR/BIKE items , a search for CAR would
only show the exclusive CAR items and not the ones which have CAr as well as
BIKE, to over come this problem i used the LIKE statement instead of the
"=" and i get the following error.
>
> Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
>
> [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax

near 'LCL'
>
>
> the code for the module is given below:
>
> function createWhereClauseFromDictionary(search_fields, table_name)
> dim tmp_str, i, col_index, db_field_val,strReplace
> tmp_str = ""
> for i = 1 to num_of_fields
> if search_fields("and_flag_" & i) = "1" then
> db_field_val = ""
> col_index = cInt(search_fields("search_fld_" & i))
> if Application(table_name)(col_index, 1) = "50" then 'bit
> if uCase(search_fields("val_start_" & i)) = "TRUE" or

search_fields("val_start_" & i) = "1" then
> db_field_val = 1
> elseif uCase(search_fields("val_start_" & i)) = "FALSE" or

search_fields("val_start_" & i) = "0" then
> db_field_val = 0
> end if
>
> else
> db_field_val = search_fields("val_start_" & i)
> end if
>
> tmp_str = tmp_str & " and " & search_fields("val_not_" & i) & "("
> if len(db_field_val) > 0 then
> tmp_str = tmp_str & Application(table_name)(col_index, 0)
> if len(search_fields("val_fin_" & i)) > 0 then 'its a range
> tmp_str = tmp_str & " >= '" & Replace(db_field_val, "'", "''") & "'"
> tmp_str = tmp_str & " and " & Application(table_name)(col_index, 0) & " <=

'" & Replace(search_fields("val_fin_" & i), "'", "''") & "'"
> else
> strReplace = Replace(db_field_val, "'", "''")
> strReplace = Trim(strReplace)
>
> ####################this is where the problem occurs####################
>
> tmp_str = tmp_str & "LIKE '" & strReplace &"'"
> ##############################################################
> end if
> else
> tmp_str = tmp_str & Application(table_name)(col_index, 0) & " is null"
> end if
> tmp_str = tmp_str & ") "
> end if
> next
> createWhereClauseFromDictionary = tmp_str
> end function
> %>
>
>
> I would really appreciate it if someone could help me out.
>
> thank you
> harsha



 
Reply With Quote
 
 
 
 
=?Utf-8?B?aGFyc2hhIG1vZ2FsaWd1bmRsYQ==?=
Guest
Posts: n/a
 
      18th Mar 2004
thanks norman that was a lot of help, appreciate it

harsha
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using a IIF statement with a Like statement Cathy Microsoft Access Database Table Design 7 10th Oct 2009 06:06 AM
retrieve only data where field name (not data) is like current mon =?Utf-8?B?U2F2ZWxpZQ==?= Microsoft Access 3 28th May 2007 10:14 PM
Poll Question : How well do you like this Father's Love Letter video presentation? (A.) I like it. (B.) I don't like it. (C.) I like it so much that it made me cry. IBMclerk7781226@yahoo.com Windows XP General 3 18th Apr 2005 02:30 AM
switch statement: Is it possible to include something like "Case var > 5" in a case statement? Juan Microsoft C# .NET 5 1st Feb 2005 06:45 PM
C# equivalent statement for vb "Like" statement? Derrick Microsoft C# .NET 4 11th Apr 2004 05:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:18 PM.