The following TSQL template may be used to perform the basic testing of your solutions for
TSQL Challenge 34 - Search for two keywords within the maximum distance of one word between them
/***********************************************************************
----------------------------------------------
BASIC Testing Sandbox for TSQL Challenge 34
Copyright © beyondrelational.com
----------------------------------------------
Notes:
1. Copy this template and paste in your SSMS Query editor
2. Insert your query (solution for TSQL Challenge 34)
in the Section between "Insert your query below"
and "Insert your query above"
3. Run the whole batch. If you see
"Invalid Results...Failed!" getting printed in output
window, there is something wrong in the query.
Revision History:
Rev 00 - 25 Oct 2010 - Jacob Sebastian - Initial Release
***********************************************************************/
/*
Create a wrapper procedure around the solution
*/
IF OBJECT_ID('tempdb..#TestSolution') IS NOT NULL BEGIN
DROP PROCEDURE #TestSolution
END
GO
CREATE PROCEDURE #TestSolution AS
BEGIN
IF OBJECT_ID('TC34_Phrases','U') IS NOT NULL BEGIN
DROP TABLE TC34_Phrases
END;
CREATE TABLE TC34_Phrases
(TextID INT,
Data VARCHAR(MAX))
INSERT INTO TC34_Phrases(TextID, Data)
SELECT 1, 'Modern technology Owes ecology An apology'
UNION ALL
SELECT 2, 'It has become appallingly obvious that our technology has exceeded our humanity'
UNION ALL
SELECT 3, 'If it keeps up man will atrophy all his limbs but the push button finger'
UNION ALL
SELECT 4, 'Our Technology presumes there is just one right way to do things and there never is'
UNION ALL
SELECT 5, 'Technology is the knack of so arranging the world that we do have to experience it'
UNION ALL
SELECT 6, 'Do you realize if it were not for Edison we would be watching TV by candlelight'
UNION ALL
SELECT 7, 'Simply put have we covered all our bases'
IF OBJECT_ID('TC34_Searches','U') IS NOT NULL BEGIN
DROP TABLE TC34_Searches
END;
CREATE TABLE TC34_Searches (
SearchID INT IDENTITY,
Text1 VARCHAR(50),
Text2 VARCHAR(50))
INSERT INTO TC34_Searches (Text1, Text2) SELECT 'all', 'limbs'
INSERT INTO TC34_Searches (Text1, Text2) SELECT 'we', 'have'
INSERT INTO TC34_Searches (Text1, Text2) SELECT 'our', 'technology';
/* Insert your query below */
/* Insert your query above */
END
GO
SET NOCOUNT ON
/*
Start the testing phase
*/
DECLARE @x TABLE(
AutoID INT IDENTITY,
SearchID INT,
TextID INT
)
-- Execute the code and
INSERT @x EXEC #TestSolution
DECLARE @z TABLE (
AutoID INT IDENTITY,
SearchID INT,
TextID INT
)
INSERT INTO @z(SearchID, TextID)
SELECT 1,3 UNION ALL
SELECT 2,5 UNION ALL
SELECT 2,7 UNION ALL
SELECT 3,2 UNION ALL
SELECT 3,4
-- Match the output with expected result.
IF EXISTS(
(SELECT * FROM @x EXCEPT SELECT * FROM @z)
UNION ALL
(SELECT * FROM @z EXCEPT SELECT * FROM @x))
BEGIN
PRINT 'Invalid Results...Failed!'
END ELSE BEGIN
PRINT 'Congratulations...Passed!'
END