473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

query filter using dynamically populated IN() function

dsatino
393 256MB
I have a query that's filtered like this:

WHERE [myfield] IN(myfunction())

if myfunction() returns only a single value, the query operates as expected. But if it returns multiple values then it returns nothing.

For example, if myfunction() returns 4 then I get results. If myfunction() returns 4,7 then it returns nothing.

I've manually changed the where statement to:
[myfield] IN(4,7) and it works fine. I've tested my function() and it returns 4,7.

It seems this should work, but it doesn't. Any ideas why. My guess is that the function is being interpreted after the SQL statement and that the 4,7 is being viewed as a single item.
May 13 '11 #1
1 1527
NeoPa
32,556 Expert Mod 16PB
Spot on. I suppose the function returns a string value. Consider what you'd expect if the value were substituted into the SQL directly :
Expand|Select|Wrap|Line Numbers
  1. WHERE [myfield] IN ('4,7')
It's a single string value, not a couple of numeric values. For that you'd need to call the function before formulating the SQL string :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "... " & _
  2.          "WHERE [MyField] In(" & MyFunction() & ")"
May 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dennis | last post by:
Hy, My english is not the best, so if you donīt understand something, please ask! I want to print the content of a mysql-table where a field is a specified value. For that i have written...
4
by: nick_faye | last post by:
hi, hope someone can help me. i am a newbie in creating queries and i want to create a query wherein i only get entries from my table where values of fields 2, 3 and 4 are not zeros. for...
4
by: Loopsludge | last post by:
ASP.NET 2.0/ SQL Server 2005/ Login Controls Does anyone know how to format a SQL query string using asp:loginname in the WHERE clause? Alternatively would I need to store the login name upon...
1
by: Sharon | last post by:
Hello All, I have a gridview control in webform which is dynamically populated on page startup with a query. I was trying to change the header text for the columns and also set wrap to false. i...
1
by: OccasionalFlyer | last post by:
I'm trying to get around the limitation of a function that accepts a string primitive but does not allow for setting attributes of that sring by using a string objet. It is not paying any...
2
by: mktilu | last post by:
i have a stored procedure in oracle 9i as given below.It return the cursor to vb6 recordset .But i dont get the Recordcount in vb6 when i excute. Oracle 9i code procedure usp_Proc1(p_cursor OUT...
3
by: Eric Lilja | last post by:
Consider this code that doesn't compile on two compilers I've tried: void foo(const char *) {} int main() { foo(new const char * ("bar")); } $ g++ -Wall -Wextra -std=c++98 -pedantic -g...
2
by: visweswaran2830 | last post by:
HI, I Want to filter a file using filesystem watcher. In that, I want to filter more than one type. Let it be, *.exe, *.java....... How can I achieve this
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.