Hello SSC,
I hope everyone is doing well!
I inherited an SSIS project that executes several stored procedures. I see global temp tables in most of the stored procedures but I cannot find the source that is building them. Does anyone have a query that can select all stored procs that contain global temp tables?
I do not see a sys.stored_procedures table. Maybe it's in a DMV?
BTW: I disagree with Global Temp tables. I do not see the need. I suppose you can use them for lookup tables and things of that nature for multiple projects, but even then, you are susceptible for the data to be inaccurate. I found that local temp tables are more than enough, especially since we have CTE's as well.
I understand why SQL has them, I just never had to use them.
Any help would be appreciated!
Dave
The are no problems, only solutions. --John Lennon
October 20, 2022 at 6:26 pm
Search for '##' in the text of the proc. The only real reason that string should be in there is to reference a global temp table.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 20, 2022 at 6:31 pm
Thank you for your response, but I am looking for a query that searches all stored procedures for the '##' sign. I can't manually check all of them we have over 500 procs.
The are no problems, only solutions. --John Lennon
SELECT OBJECT_NAME(object_id) AS object_name
SUBSTRING(definition, CHARINDEX('##', definition) - 20, 200) AS definition_first_match,
definition
FROM sys.sql_modules
WHERE definition LIKE N'%##%'
ORDER BY 1
Edit: Sorry, I should have been clearer with code. I never expected anyone to do a non-computer search for the string.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 20, 2022 at 6:58 pm
Thank you for your response, but I am looking for a query that searches all stored procedures for the '##' sign. I can't manually check all of them we have over 500 procs.
well.... you can (and should) have them already on a Visual Studio solution where the search would be fast and would give you ALL occurrences of it.
maybe its time to do it. - and put them on a source control repository
October 20, 2022 at 7:37 pm
Fredrico,
Are you suggesting searching in Management Studio or Visual Studio. I am not sure if I have searched the way you are suggesting.
Thank you so much for your response!
Dave
The are no problems, only solutions. --John Lennon
October 20, 2022 at 7:39 pm
Thank you Scott!!
This is exactly what I need.
The are no problems, only solutions. --John Lennon
October 20, 2022 at 9:01 pm
Lord Slaagh wrote:Thank you for your response, but I am looking for a query that searches all stored procedures for the '##' sign. I can't manually check all of them we have over 500 procs.
well.... you can (and should) have them already on a Visual Studio solution where the search would be fast and would give you ALL occurrences of it.
maybe its time to do it. - and put them on a source control repository
I totally agree with the "Source Control" suggestion but, even if I used VS, I'd still use a search on the definition, just to be sure. Been burned too many times by :features".
--Jeff Moden
Change is inevitable... Change for the better is not.
October 21, 2022 at 4:41 pm
And if you want to search all databases at the same time:
exec sp_MSforeachdb 'use [?] select ''?'' as dbName, name as ''SP_Name'', obj.type,
substring(definition,CHARINDEX(''##'', definition)-45,150) as ''Code_Snippet''
from sys.sql_modules com
join sysobjects obj on com.object_id = obj.id
where (definition like ''%##%'')
and ''[?]'' <> ''Omit_This_DB''
order by dbName, name'
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy