Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IN operator in parameterized remote view.
Message
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00520273
Message ID:
00520646
Views:
19
Daniel,

Thanks, that did the trick. I should have caught that (the leading comma delimiter).

Thanks so much for your time!

>James,
>Sorry, my mistake. We'll get it right this time ;-)
>
>lcList = ',100,101,102,103,'
>lcCmd  = 'select cname from customers where CHARINDEX(','+RTRIM(CAST(icustomerid as char(20)))+',', ?lcList)>0'
>? sqlexec(lnHandle,lcCmd)
>
>HTH
>
>>Daniel,
>>
>>I still get the same result. Is there something I'm missing? I copied your code exactly and still get the same result set.
>>
>>Thanks for your assistance.
>>
>>>James,
>>>Simply add the comma (or any other separator) to the search expression. Make sure that lcList terminates with the separator:
>>>
>>>lcList = '100,101,102,103,'
>>>lcCmd  = 'select cname from customers where CHARINDEX(RTRIM(CAST(icustomerid as char(20)))+',', ?lcList)>0'
>>>? sqlexec(lnHandle,lcCmd)
>>>
>>>HTH
>>>>Daniel,
>>>>
>>>>Thanks for the info. That is getting closer. However, this solution has problems when the lcList has comma-delimited values that are greater than single digits.
>>>>
>>>>For example, the following lcList string:
>>>>
>>>>lcList = ['100','101','102','103']
>>>>
>>>>Returns the following result set:
>>>>
>>>>iCustomerId
>>>>===========
>>>>1
>>>>2
>>>>3
>>>>10
>>>>100
>>>>101
>>>>102
>>>>103
>>>>
>>>>Do you have any other tricks up your sleeve or a modification to the above?
>>>>
>>>>Thanks again for your help!
>>>>
>>>>
>>>>>James,
>>>>>Assuming that your backend is SQL Server, the following should work:
>>>>>
>>>>>lcList = ['1','2','3','4']
>>>>>lcCmd  = 'select cname from customers where CHARINDEX(RTRIM(CAST(icustomerid as char(20))), ?lcList)>0'
>>>>>? sqlexec(lnHandle,lcCmd)
>>>>>
>>>>>It's a bit of a hack, but it works :-)
>>>>>The CHARINDEX() function is similar to VFP's AT() function and returns the starting position of the specified expression in a character string.
>>>>>
>>>>>HTH
>>>>>>I'm having difficutly using the IN operator in the parameter statement in a remote view against a SQL Server table. Here is my view:
>>>>>>
>>>>>>CREATE SQL VIEW "V_CUSTOMERS" ;
>>>>>> REMOTE CONNECT "My_Connection" AS ;
>>>>>> SELECT ;
>>>>>> Customers.icustomerid,;
>>>>>> Customers.cname,;
>>>>>> Status.cstatus ;
>>>>>> FROM Customers ;
>>>>>> LEFT JOIN Status ON Status.istatusid = Customers.istatusid ;
>>>>>> WHERE CAST(Customers.icustomerid as CHAR(20)) IN (?vp_cCustomerIdList) ;
>>>>>> ORDER BY Customers.cname
>>>>>>
>>>>>>I tried performing this same operation using SPT in the following statement:
>>>>>>
>>>>>>lcList = '1,2,3,4'
>>>>>>lcCmd = 'select cname from customers where cast(icustomerid as char(20)) in (?lcList)'
>>>>>>? sqlexec(lnHandle,lcCmd)
>>>>>>
>>>>>>I have tried changing the parameter (lcList) to the following without success:
>>>>>>
>>>>>>lcList = ['1','2','3','4']
>>>>>>
>>>>>>If I don't execute this as a parameter, then it will work:
>>>>>>
>>>>>>lcCmd = 'select cname from customers where cast(icustomerid as char(20)) in (' + lcList + ')'
>>>>>>? sqlexec(lnHandle,lcCmd)
>>>>>>
>>>>>>I really need to set this up as a parameterized view. Is there something that I am missing here or is what I am trying to accomplish just not work?
>>>>>>
>>>>>>Please help! I really would appreciate it.
>>>>>>
>>>>>>TIA,
>>>>>>
>>>>>>James
James Moore
Owner/Developer
Ministry Tracking Software, Inc.
www.youthtrack.com
Previous
Reply
Map
View

Click here to load this message in the networking platform