SQL Server 2008 Management Studio – Running Parameterized Query

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?


Add Comment
2 Answer(s)

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,,>%'   
Answered on July 15, 2016.
Add Comment

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
Answered on July 15, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.