SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Dynamically Generating HTML Tags from T-SQL

By Cade Bryant, 2003/04/11

Total article views: 96 | Views in the last 30 days: 5

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).

By Cade Bryant, 2003/04/11

Total article views: 96 | Views in the last 30 days: 5
Your response
 
 
Related tags

T-SQL Aids    
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com