A technical blog about my projects, challenges, and discoveries in the world of data warehousing using SQL Server, Power BI Desktop, DevExpress, and more.

Tuesday, September 8, 2009

Posting SQL Code to HTML Pages

This is just a quick post with a simple heads-up when you want to post query code to an HTML environment, such as a web page or a blog entry. I have learned the hard way that the one symbol commonly used in SQL statements can trip up an HTML post: the "less than" symbol. This symbol is <, of course. It seems innocent enough, but in HTML environments the "less than" symbol is ALSO the "open HTML tag" symbol. An HTML page will expect some kind of tag information after that symbol, and when there is not an expected piece of HTML code after it, the results will be undesirable.

Worse, a blog editor such as blogger may lose the unrecognized text that comes after the symbol, causing the need to redo much of the work of creating the query statement. For example, I just had to redo a post I put up a couple of weeks ago because of a "less than" comparison in the query statement. After I posted it, parts of my code disappeared, and when someone tried to use it, she just got an error message. I only heard from one person, but anyone who tried to use it would have gotten nowhere with it. It's fixed now, so don't worry about having to figure out which one it was.

If you want to publish a SQL statement in an HTML environment, you will need to edit the HTML before you publish it. All you have to do is replace the "less than" symbol with the HTML-friendly code of & l t ; (without the spaces; I had to add spaces so the code wouldn't change into the symbol in this post) instead. You might want to change the "greater than" symbol to & g t ; (again, don't put in the spaces) while you're at it.

No comments:

Post a Comment