Avatar of Dovberman
Dovberman
Flag for United States of America asked on

TSql Syntax, H0w to set a parameter

I need to substitute a parameter value into sql syntax as follows:

ALTER PROCEDURE [dbo].[usp_getUTestArray]
      -- Add the parameters for the stored procedure here
      @SymbolID int,
      @HistRange smallint
      
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

    -- Insert statements for procedure here
      SELECT TOP 18 SymbolID,ClosePrice,QuoteDate
      FROM StockHist
      WHERE
      SymbolID = @SymbolID
      AND QuoteDate <= (SELECT TOP 1 QuoteDate
            FROM DownLoadDates
            WHERE MarketID=2
            ORDER BY QuoteDate DESC )
      ORDER BY QuoteDate DESC

@HistRange is 18.

I need the equivalent of

SELECT TOP @HistRange  SymbolID,ClosePrice,QuoteDate
      FROM StockHist


Can this be done?

Thanks,
Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
Dovberman

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Aneesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dovberman

ASKER
Thank you.
Dovberman

ASKER
Thank you.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck