Stored Procedure

Results 1 to 3 of 3

Thread: Stored Procedure

  1. #1
    Mark Guest

    Default Stored Procedure

    Hi all,<BR>Anyone know how to apply a variable in a stored procedure so that a column SELECT can be cotrolled externally? <BR>I have tried the following with no success.<BR><BR>CREATE PROCEDURE deliveryOptions <BR>(@ldelivery_zone char)<BR>AS<BR>SELECT del_id, ["zone" + @ldelivery_zone] <BR>FROM delivery<BR><BR>I have several columns in a table: zone1, zone2 etc. I am trying to control the column SELECT via @ldelivery_zone variable... but have had no success!<BR><BR>Thanks in advance.<BR>Rgds Mark.

  2. #2
    Join Date
    Dec 1969

    Default RE: Stored Procedure

    You&#039ll have to build the entire select statement as a string and assign it to a var then use EXECute:<BR><BR><BR>CREATE PROCEDURE spTest<BR>@pValues varChar(1)<BR>AS<BR>DECLARE @sSql VarChar(100)<BR><BR>SELECT @sSql = &#039SELECT FieldName&#039 + @pValues + &#039 FROM Blah Blah ...&#039<BR>EXEC(@sSql)<BR><BR><BR>

  3. #3
    Mark Guest

    Default RE: Stored Procedure

    Thanks g-mny :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts