Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could I embed HTML tags into SQL ?

Status
Not open for further replies.

omid020

Technical User
Jul 15, 2007
28
IR
Hi ,
Can I mix my SQL code with some HTML tags ?
Let`s assume that this is main code :
Code:
Select projects.projectName,
       projects.pictureName
Could I have something like this one instead of that :
Code:
Select projects.projectName,
       <img src="./pics/projects.pictureName" />

projects.pictureName is some data like firstproject.gif or secondproject.png ;

If I couldn`t do it how can I prepare my code for working with any HTML interpreter ?
 
You could do this:

Code:
Select Projects.ProjectName,
       '<img src="./pics/' + projects.PictureName + '" />' As ImageSource

Personally, I think it would be best to do this in your front end though. I assume it's something like asp, asp.net, php, coldfusion, etc... I think it would be better to add the img tag there instead of in the SQL code.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Yes, you can do this in Select Statement, if you want. We did use some complex scripts in Select Statement (my colleague embedded them). I remember I was trying to somehow incorporate this into SP, but could not get it working, so I left it in the page as direct in-line SQL.

Here is a sample of what we were having:

Code:
SelectCommand="SELECT Events.EventID, Events.EventName,Events.Description AS Description, CASE Events.Description WHEN '' THEN '-' ELSE('<div onClick=&quot;content(this,0)&quot; class=&quot;hand&quot;>'+substring(Events.Description,1,50)+'&nbsp;&hellip;&nbsp;&raquo;</div><div class=&quot;more&quot; ><div class=&quot;fr X&quot; onClick=&quot;content(this,1)&quot;>X</div>'+Events.Description+'</div>') END AS DescriptionMore, Events.EventTime, Events.EndTime, Events.EventLocation, Events.Fee, Events.GearedFor, Events.VolunteersReq, Events.Canceled, Coordinators.FirstName + ' ' + Coordinators.LastName AS Coordinator, Events.CoordinatorID, CASE dbo.GetEventTargets(Events.EventID) WHEN '' THEN '-' ELSE('<div onClick=&quot;content(this,0)&quot; class=&quot;hand&quot;>'+substring(dbo.GetEventTargets(Events.EventID),1,15)+'&nbsp;&hellip;&nbsp;&raquo;</div><div class=&quot;more&quot; ><div class=&quot;fr X&quot; onClick=&quot;content(this,1)&quot;>X</div>'+dbo.GetEventTargets(Events.EventID)+'</div>') END AS TargetPop, Events.Facilitator FROM Events LEFT OUTER JOIN Coordinators ON Events.CoordinatorID = Coordinators.CoordinatorID WHERE Coordinators.SiteID = @SiteID"

as you see - very complex stuff.
 
BTW, now when I posted this SQL I see an obvious error in it - why we're using a LEFT JOIN with Coordinators and with WHERE condition on Coordinator?

Obviously it converts it automatically to an INNER JOIN.

I'm no longer work there, so I don't know if I should send this to my former colleague or they already found it and fixed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top