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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return string from function 1

Status
Not open for further replies.

rsshetty

Programmer
Dec 16, 2003
236
US
Here's my problem

I have a table

title link
------------
A page1.asp
B Page2asp
C Page3.asp

I want to construct a string with the foll. format.

'<td><a href="page1.asp">A</td><td><a href="page2.asp">B</td><td><a href="page3.asp">C</td>'

I want to be able to construct the above string in a function and return it.

Is it possible?




rsshetty.
It's always in the details.
 
Try this, Only limitation is that the variable can hold only 8000 Characters

Declare @Str varchar(8000)

Set @Str = ''

Select @Str = @str + '<td><a href="' + link + '">' + title+'</td>' from TBLName order by title asc

print @str


Sunil
 
I'm sorry but I have a degree of difficulty to add to it.

I want something like this:

select
case when ID%5 <> 0 then
@str = @str + '<td>'+title+'</td>'
else
@str = @str + '</tr><tr><td>'+title+'</td>'
end
from fairmodulenavigation a where usergroup = 'A'

Ofcourse this is incorrect..I want to know the right syntax for it.

rsshetty.
It's always in the details.
 
Can you explain how exactly ur data looks like and what output you are expecting?



Sunil
 
ID title link
------------
1 A page1.asp
2 B Page2asp
3 C Page3.asp
4 D Page4.asp

The output
A B
C D
(where A,B,C,D are hyperlinked on the webpage) I need to add a <tr> tag after B.
Hope this helps.


rsshetty.
It's always in the details.
 
Try this

Declare @Str varchar(8000)

Set @Str = '<table>'

Select @Str = @str +
Case When ID%2=1 Then '<tr>' Else '' End +
'<td><a href="' + link + '">' + title+'</td>'
+ Case When ID%2=0 Then '</tr>' ELse '' End
from TBLNAME order by title asc

Set @Str = @str + case When Right(@str,5) = '</tr>' Then '</table>' Else '</tr></table>'End

print @str


Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top