sql stored procedure question

Results 1 to 2 of 2

Thread: sql stored procedure question

  1. #1
    Join Date
    Dec 1969

    Default sql stored procedure question

    Can I do something like what i am trying to do with the following code?.. I&#039;m not quite sure on the syntax i am meant to be using. The main thing I cant work out is how to do a select statement and return a value into a variable that I can then use as the WHERE clause on my update.<BR><BR>-- this sp handles update css stuff<BR><BR>CREATE PROCEDURE updateCSS<BR>@updateID Int,<BR>@txtBodyColor NVarChar(255),<BR>@txtNav1Color NVarChar(255),<BR>@txtNav1Font NVarChar(255),<BR>@txtNav1Size NVarChar(255),<BR>@txtHeadingColor NVarChar(255),<BR>@txtHeadingSize NVarChar(255),<BR>@txtHeadingFont NVarChar(255),<BR>@txtNav2Color NVarChar(255),<BR>@txtNav2Size NVarChar(255),<BR>@txtNav2Font NVarChar(255)<BR>As<BR><BR>--get update id to use<BR>SELECT tblTemplate.tCSS AS @updateID FROM tblTemplate WHERE tblTemplate.isActive = 1;<BR><BR>--update table using updateID i just got...<BR>UPDATE tblCSS SET<BR> tblCss.cBodyBackColor = @txtBodyColor,<BR> tblCss.cNav1Textcolor = @txtNav1Color, <BR> tblCss.cNav1TextSize = @txtNav1Size, <BR> tblCss.cNav1TextFont = @txtNav1Font, <BR> tblCss.cNav2TextColor = @txtNav2Color,<BR> tblCss.cNav2textSize = @txtNav2Size,<BR> tblCss.cNav2Font = @txtNav2Font,<BR> tblCss.cPageHeadingColor = @txtHeadingColor, <BR> tblCss.cPageHeadingSize = @txtHeadingSize,<BR> tblCss.cPageHeadingFont = @txtHeadingFont<BR><BR> Where tblCSS.cssID = @updateID;<BR>GO

  2. #2
    Join Date
    Dec 1969

    Default RE: sql stored procedure question

    Well first of all, if you&#039;re getting @updateID from the tblTemplate table, you don&#039;t need it in the input parameters. Declare it after the start of the stored proc instead:<BR><BR>DECLARE @updateID INT<BR><BR>Second, to store the result of your first SELECT statement in this variable, you need a slight change of syntax:<BR><BR>SELECT @updateID = tblTemplate.tCSS FROM tblTemplate WHERE tblTemplate.isActive = 1<BR><BR>HTH<BR><BR><BR>

Posting Permissions

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