SQL Server 2008 Management Studio - Running Parameterized Query

13,385

Solution 1

I don't believe this is possible.

What I usually do in this case is just add the following to the top of the window:

declare @id int
set @id = 10

-- followed by the parameterized query

Actually, I think 2008 supports initialization now:

declare @id int = 10

Solution 2

I would typically use the CTRL-Shift-M functionality in SSMS. See following example with instructions. Bit tedious but hey, better than nothing.

--===============================================  
-- Purpose: Search all objects for specified Text  
--===============================================  
-- Instructions: CTRL-A + CTRL-Shift-M, enter text   
-- to search, click Ok and press F5.  
-- To repeat search with other text: CTRL-Z (undo)  
-- and then repeat above.  
SELECT o.Name   AS [Object Name]  
    ,o.xType AS [Object Type]  
    ,s.TEXT  AS [Object Text]  
FROM sySobjects o,  
     sysComments s  
WHERE  o.Id = s.Id  
  AND TEXT LIKE '%<Text To Search,,>%'   
Share:
13,385
Jarrod Dixon
Author by

Jarrod Dixon

Former Developer on the Stack Overflow team. Was dubbed SALTY SAILOR by Jeff Atwood, as filth and flarn would oft-times fly when dealing with a particularly nasty bug! Twitter me: jarrod_dixon Email me: [email protected]

Updated on June 25, 2022

Comments

  • Jarrod Dixon
    Jarrod Dixon almost 2 years

    I'd like to be able to run an already parameterized query from within the SSMS:

    select name
    from aTable
    where id = @id
    

    I know that other IDEs (e.g. TOAD) allow for parameter binding - is this available in SSMS 2008?

    Thanks!

  • Jarrod Dixon
    Jarrod Dixon over 15 years
    Yeah, that's what I'm doing, too - I had hoped for something along the lines of the Template Parameter binding feature :)