473,405 Members | 2,310 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,405 software developers and data experts.

SQL procedure parameters

Hi everyone,

I need to create a procedure that would take the two parameters @FieldName
and @FieldValue and replaces it in my SQL statement without using Exec
because Exec can take at most 128 characters.

CREATE PROCEDURE Get_Person_By_Field
@FieldName varchar(20),
@FieldValue varchar(100)
AS
..
..
..

INSERT INTO
#TempPerson(PID,Title,PhNum1,PhExt1,PrimaryEmail,F ullName,CompanyName

) SELECT PID,Title, PhNum1, PhExt1,PrimaryEmail,FullName, CompanyName FROM
Person LEFT JOIN Company ON Person.CID = Company.CID WHERE
@FieldName='@FieldValue'

Thank you
Maz.


Jul 20 '05 #1
1 7146
Maziar Aflatoun (ma***@rogers.com) writes:
I need to create a procedure that would take the two parameters @FieldName
and @FieldValue and replaces it in my SQL statement without using Exec
because Exec can take at most 128 characters.

CREATE PROCEDURE Get_Person_By_Field
@FieldName varchar(20),
@FieldValue varchar(100)
AS
.
.
.
INSERT INTO
#TempPerson(PID,Title,PhNum1,PhExt1,PrimaryEmail,F ullName,CompanyName

)
SELECT PID,Title, PhNum1, PhExt1,PrimaryEmail,FullName, CompanyName FROM
Person LEFT JOIN Company ON Person.CID = Company.CID WHERE
@FieldName='@FieldValue'


If you are doing things like this, chances are good that you have a
flawed designed.

In any case, this is possible to achieve with sp_executesql, or EXEC() for
that matter. I don't know what you mean with 128 characters. Possibly you
are doing the mistake of saying

EXEC @sql

Here you @sql cannot be longer than 128 chars, unless there are periods
in the string, as @sql here should be the name of a stored procedure. The
correct syntax for dynamic SQL is EXEC(@sql). But sp_executesql is better,
see http://www.sommarskog.se/dynamic_sql.html#sp_executesql.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

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

Similar topics

10
by: Chopper | last post by:
I have a stored procedure that takes parameter @description with datatype set to text. In my ASP I have the following: ..Parameters.Append...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
0
by: Craig Faulkner | last post by:
I have been fighting through my first crystal report in VS2003.NET and have made some headway. Here is what I've done: 1. Created a crystal report in VS2003 from a SQL stored procedure with...
1
by: Johnny | last post by:
I have a stored procedure that takes three input parameters and returns a single record result set. The stored procedure is declare as follows: p_getTaxAmount (@ZipCodeDtlId uniqueidentifier,...
8
by: Konstantin Andreev | last post by:
Hello, everybody. I've noticed very strange DB2 behaviour in a stored procedure parameters handling, and it looks like a bug for me. Consider stored procedure defined as: Create procedure...
3
by: Brett Wickard | last post by:
Anyone know of a good way to autogenerate stored procedure parameters to put into c# code? I don't need to do it on the fly, just while coding. I've got some SPs with a lot of parameters, so it...
0
by: Mariana | last post by:
Hello, I am exporting reports in pdf format from .net 2005 . The export is working fine; however the user values of stored procedure parameters does not show in the report. What do I need to do in...
2
by: R2d2Rabeau | last post by:
Hi, How can I pass values from a List as stored procedure parameters? name= "Smith", age = 21 name="Brown", age =46 name="White", age=28 ... // data added to the List
0
by: chichbong | last post by:
I have a form in an .adp file in Access 2007, and the project is connected to SQL Server 2005. The form uses a stored procedure to display records. The stored procedure does a JOIN of 2 tables, and...
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
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.