Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-03-09 : 08:41:29
|
| Tom writes "Is it improper or poor practice to use SQL DML to generate rows of HTML Markup? For example, options for a select box:SELECT DISTINCT job,'<option value = "'+ jobId + '">'+ job + '</option>' AS optFROM jobTableWHERE job LIKE '%CLERK%'I have been told that MSSQL Server is inefficient and slow when it is expected manipulate strings. Yet I have seen countless examples in trade books where DML is employed to format data. Why not use it to generate HTML when manipulating small < 3K records sets?Thanks!" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-03-09 : 08:44:02
|
Generally speaking, you should NEVER do what you're doing here.BUT...I also use this technique for small resultsets, and it works very well. The biggest problem you'll have is using this technique appropriately. As long as you don't use it for everything you'll do fine.And SQL Server isn't all that inefficient in string manipulation, but when you compare it to regular expressions then yes, it is pretty limited. |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-03-09 : 08:52:48
|
| The biggest problem I see with that sort of thing, is if you write a proc that does what this example shows, it is TOTALLY useless for anything else.If you need to pull out the same data to show it in an HTML table, you have to go write another proc.You are better off writing a function or sub in ASP (or whatever you're using) that you can pass an array to, or a single record and have it do the formatting for you. You are still saving yourself the grief of formatting each row this way, but also keep the reusability of the proc.Damian |
 |
|
|
|
|
|