SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Monday, June 05, 2006

Stored Procedure question

SQL Apprentice Question
Hi
I am looking to write a stored procedure that uses a string inside the
IN statement but am having trouble with the syntax.

ex.
Create Procedure spMyProcedure
@bookID varchar(80)
AS
SELECT * FROM books WHERE bookID IN(@bookID)


I've tried this and it does not work. How would I pass in a comma
separated string so that the IN clause works?



Celko Answers

>> I am looking to write a stored procedure that uses a string inside the IN statement but am having trouble with the syntax. <<


No, you are having trouble with the most basic programing concepts --
not just SQL, but the most basic programing concepts. You have no
idea;

1) What a parameter is
2) How a compiled language works
3) What First Normal Form is and why it is important (okay, this is SQL
and not MVDBMS)


Do not feel like the Lone Ranger. This error is posted a few times a
month along with EAV, OTLT, MUCK and RTFM. Those misconceptions about
the RDBMS have names, which makes them easier to handle and to Google.


I propose a contest for a name for this piece of non-RDBMS disaster. I
will start with "NFNF parameters" of NFNFP for short. but it does not
flow off the tongue; can someone do better?

No comments: