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

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Dynamically Generating HTML Tags from T-SQL

By Cade Bryant,

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: 665 | Views in the last 30 days: 2
Related Articles

Product Levels

Hierarchy in Product Levels


production Support

Help needed in production support


Help with Query - Products

Help With query - Products


deploying sp into production

deploying sp into production


Globalisation of my product

Globalisation of my product


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

Already a member? Jump in:

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