Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Dynamically Generating HTML Tags from T-SQL

By Cade Bryant, 2013/05/21

Here's a real-life challenge I was faced with at work: my company (a talent agency) needed me to create a report listing all of our actors that we represent - and for each actor, a comma-delimited string of each production that they've starred in.  Simple enough, right......except that, within the comma-delimited list of productions, they wanted those productions that were "theatre" productions to be shown in italics!

Luckily, the front-end tool that would display the data was HTML-aware.  So, the challenge became, "How do I dynamically generate the appropriate HTML tags around each item in the list that's in the theatre category?"

Below is the code I came up with to do this.  Of course, I have simplified it greatly, and am using some "dummy" tables in this example,  But at least you can get the concept from the example below.  (Note: this uses a UDF, so it will only work in SQL 2000.  If you're using version 7, you must extract the code and run it as straght SQL).

Total article views: 619 | Views in the last 30 days: 3
 
Related Articles
FORUM

Product Levels

Hierarchy in Product Levels

FORUM

production Support

Help needed in production support

FORUM

Help with Query - Products

Help With query - Products

FORUM

deploying sp into production

deploying sp into production

FORUM

Globalisation of my product

Globalisation of my product

Tags
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones