473,385 Members | 1,973 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,385 software developers and data experts.

Dynamic sets? (i.e. where x in (@set))

Hi,

I've tried without success to create a function where one of the
parameters determines the final line of a select statement.

The final line includes a 'where referencenumber in (@set)' line.. and
@set is the parameter I wish to use which is a string.

If the set is just one value, it works fine, however with anything more
than that I just get no records returned.. If I output the parameter,
and copy and paste that into query analyser I do get the correct result,
so it's nothing to do with string delimiters etc..

Any ideas to fix this problem? Or am I going to have to dynamic sql the
whole thing?

Cheers,
Chris

Jul 20 '05 #1
2 1206
Take a look at this for a good overview of techniques
http://www.sommarskog.se/arrays-in-sql.html

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
>> The final line includes a 'where referencenumber in (@set)' line..
and @set is the parameter I wish to use which is a string. <<

There is nothign wrong with a string dataytpe parameter. Apparently,
you don't know that parameters are SCALAR, not data structures. There
is one and only data structure in SQL, the table. Furthermore, SQL is
a COMPILED LANGUAGE, not an interpreter.
If the set is just one value, it works fine, however with anything more than that I just get no records [sic] returned.. <<

Rows are not anything like records. Chris, you have missed the
foundations of the RDBMS model. I can give a dangerous kludge in the
form of single SQL statement that runs like glue while it parses a CSV
string and CAST() the piece into the target datatype (which you did
not tell us, along with the DDL that you did not post).
Any ideas to fix this problem? Or am I going to have to dynamic sql

the whole thing? <<

The right way to do this is the load a table with values, add
constaints to this table and make sure that you don't invite dirty
data:

In the schema, build your set and clean it up

CREATE TABLE PickList
(pick INTEGER NOT NULL PRIMARY KEY
CHECK (pick BETWEEN 1 AND 100));

In the front end, load the set:
DELETE FROM PickList;
INSERT INTO Picklist VALUES (..);

When SQL Server finally gets to the 1992 Standards a dozen years late,
this can be done in one INSERT statement, but for now you have to
write procedural code.

SELECT..
FROM ..
WHERE x IN (SELECT pick FROM PickList);

More work? Yes! Safer, portable, and fast? Yes, much!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Raymond Hettinger | last post by:
I've gotten lots of feedback on the itertools module but have not heard a peep about the new sets module. * Are you overjoyed/outraged by the choice of | and & as set operators (instead of + and...
7
by: pysim | last post by:
Hi, I have a couple of general requests for pointers to python examples and design advice. I'm looking for examples of MVC-based GUI controls done in python (model-view-controller). Also,...
1
by: Gerrit Holl | last post by:
Brett C. wrote: > Sets now at blazing C speeds! > ----------------------------- > Raymond Hettinger implemented the sets API in C! The new built-ins are > set (which replaces sets.Set) and...
1
by: David Vaughan | last post by:
I was expecting the class sets.Set to act like an unordered list with no two members equal. But, while the following code prints True, the assertion fails. from sets import Set _base = str...
5
by: Istvan Albert | last post by:
Hello all, if I have this code: import sets class Foo: x = sets.Set() then pychecker says:
6
by: Paul Rubin | last post by:
I'm thinking of proposing that a values method be added to set objects, analogously with dicts. If x is a set, x.values() would be the same as list(x). This feels logical, and it would allow...
6
by: John Henry | last post by:
Hi list, If I have a bunch of sets: a = set((1, 2, 3)) b = set((2, 3)) c = set((1, 3)) ..... What's the cleanest way to say:
2
by: mkppk | last post by:
I have kind of strange change I'd like to make to the sets.Set() intersection() method.. Normally, intersection would return items in both s1 and s2 like with something like this: ...
13
by: jm.suresh | last post by:
It is not possible to index set objects. That is OK. But, what if I want to find some element from the Set. from sets import Set s = Set( range(12 ) if I do pop, that particular element gets...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.