Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
A list of one owl's 5 favourite system stored procedures in SQL! Part two of a six-part series of blogs |
---|
Everyone has a favourite system stored procedure (you do, don't you?). But five? That's the subject of this blog, anyway.
|
This has to be the most fun system stored procedure, although maybe I just think so because I don't get out enough. Let's suppose you've created a stored procedure:
CREATE PROC spExample
AS
-- list out all films
SELECT
f.Title
, f.OscarWins AS Oscars
, f.RunTimeMinutes AS RunTime
FROM
Film AS f
ORDER BY
f.Title
You now want to find all the lines containing commas. So you use sp_helptext:
-- analyse this procedure
sp_helptext 'spExample'
The results are a bit weird:
The lines which comprise your stored procedure!
You could put the results in a temporary table, and use this to show all the lines containing commas:
DECLARE @lines TABLE(
LineText VARCHAR(MAX)
)
-- put lines of procedure into table
INSERT INTO @lines
EXEC sp_helptext 'spExample'
-- now show lines beginning with commas
SELECT
LineText
FROM
@lines
WHERE
LineText LIKE '%,%'
The results are impressive:
The two lines containing commas.
I'm not QUITE sure how you'd use this information, but sometimes the fun is in the answer, not how it's used! For how to write your own stored procedures, consider booking a place on our Advanced SQL course.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.