TSQL Challenge 17 - Creating cross rows references with inline hyperlinks
This is a very interesting challenge which we saw in one of the online forums. The task involves generating HTML tags (hyper links) around certain keywords in the value of a column.
Sample Data
id keyword data
---- -------------------- -----------------------------------
1 Pet Store Microsoft SQL Server
2 SQL Server Database Dinner at a New York Restaurant
3 Restaurant Welcome to TSQL Challenges 17
4 New York Bob is a Database Expert
5 TSQL Challenges Is Microsoft Listening?
6 Microsoft New Challenges are coming up
Expected Output
id keyword data
---- -------------------- -----------------------------------------
1 Pet Store <a href="tsql.com?id=6">Microsoft</a> SQL
Server
2 SQL Server Database Dinner at a <a href="tsql.com?id=4">New
York</a><a href="tsql.com?id=3">Restaurant
</a>
3 Restaurant Welcome to <a href="tsql.com?id=5">TSQL
Challenges</a> 17
4 New York Bob is a Database Expert
5 TSQL Challenges Is <a href="tsql.com?id=6">Microsoft</a>
Listening?
6 Microsoft New Challenges are coming up
Sample Data
Use the following script to generate the sample data needed for this challenge
DECLARE @t TABLE(
id TINYINT,
keyword VARCHAR(20),
data VARCHAR(35)
)
INSERT INTO @t(id, keyword, data)
SELECT 1, 'Pet Store', 'Microsoft SQL Server'
UNION ALL
SELECT 2, 'SQL Server Database', 'Dinner at a New York Restaurant'
UNION ALL
SELECT 3, 'Restaurant', 'Welcome to TSQL Challenges 17'
UNION ALL
SELECT 4, 'New York', 'Bob is a Database Expert'
UNION ALL
SELECT 5, 'TSQL Challenges', 'Is Microsoft Listening?'
UNION ALL
SELECT 6, 'Microsoft', 'New Challenges are coming up'
SELECT * FROM @t
- Read the Submission Guidelines and make sure that your solution follows them.
- The solution should work on SQL Server 2005, 2008 or later versions
- Last date to submit your entries: 30-Nov-2009 Midnight GMT
- Use this forum for any questions related to TSQL Challenge #17
| Syntax Bookmark of the Day! – Database Mirroring |
|
|
About the Authors.
Challenge Evaluation Details
Though the evaluation of this TSQL Challenge is completed and winners are announced, you can still submit a solution and we will be very happy to review it. Before submitting, make sure that your solution passes the basic testing and logic testing and the performance statics are good. See the submission guidelines before submitting your solution.