Simple Stored Procedure problem.

Simple Stored Procedure problem.

Post by Casper_Spil » Thu, 15 Nov 2001 07:31:37



I am trying to turn a working SQL statement into an SP. The error
occurs when I try to use three parameters in a row, which are all
passed from a web page.

CREATE PROCEDURE [search_tool]

AS
tables.columns etc...

FROM table1 etc...

WHERE table1.column4 > '0'
AND TABLE.column1 = 'TO_THIS'

Any advice would be great.

Sam

 
 
 

Simple Stored Procedure problem.

Post by oj » Thu, 15 Nov 2001 07:48:15


casper,

dynamic query is your solution...informative stuff at erland's site..

http://www.algonet.se/~sommar/dynamic_sql.html

-oj


> I am trying to turn a working SQL statement into an SP. The error
> occurs when I try to use three parameters in a row, which are all
> passed from a web page.

> CREATE PROCEDURE [search_tool]




> AS
> tables.columns etc...

> FROM table1 etc...

> WHERE table1.column4 > '0'
> AND TABLE.column1 = 'TO_THIS'

> Any advice would be great.

> Sam


 
 
 

Simple Stored Procedure problem.

Post by Joe Celk » Thu, 15 Nov 2001 08:07:12


You can do this with dynamic SQL, but it is a bad idea.  The procedure is too general to be part of an application.  Think about it.  Why are you letting the user search on anything in the table?  And why is EVERY column in the table a CHAR(n) or VARCHAR(n)?  While that is possible, it is very unlikely unless your schema is an absolute nightmare that mimics a 1950's Cobol program.  

--CELKO--
 ===========================
 Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, datatypes, etc. in your schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Simple Stored Procedure problem.

Post by Gert-Jan Stri » Fri, 16 Nov 2001 01:43:21


I agree with Joe that your approach is too generic and will get you into
problems.

If you insist on doing it in such a way, then I would suggest you put
together your queries in your frond-end programming language such as VB
or C++, and send simple SQL statements to SQL-Server. SQL-Server is not
very good at copying and pasting SQL statements on the fly. You will get
messy dynamic HTML.

Hope this helps.
Gert-Jan


> I am trying to turn a working SQL statement into an SP. The error
> occurs when I try to use three parameters in a row, which are all
> passed from a web page.

> CREATE PROCEDURE [search_tool]




> AS
> tables.columns etc...

> FROM table1 etc...

> WHERE table1.column4 > '0'
> AND TABLE.column1 = 'TO_THIS'

> Any advice would be great.

> Sam

 
 
 

1. Many Simple Stored Procedures VS. Few Complex Stored Procedures

Hi, I was wondering if anybody could enlighten me as to whether it is
GENERALLY more advantageous to build a couple of very complex stored
procedures with many IF ELSE conditions to handle multiple scenarios
or to simply build many simple stored procedures to handle each
situation.  Which alternative would result in faster processing by SQL
Server?

Your feedback is much appreciated!

Darren

2. log analyzer?

3. Help on simple simple stored procedure

4. want to leave the mailinglist

5. Problem with simple stored procedure?

6. Can I import from 7.0 to 2000?

7. variable temp table name, a ~simple~ string problem in stored procedures

8. How to access SQL Server 7 via ODBC-32 and VB3

9. Problem with stored procedure that calls other stored procedures

10. Problem compiling stored procedure that calls another stored procedure

11. Stored procedures problem using DB2 Stored Procedure Builder

12. Calling a Java Stored Procedure from another Java Stored Stored Procedure

13. A simple question on Stored procedure with parameter