Old Code:
set @mysql = N'set @mystrmax = (select tdline, tddesc from ' + @timedesc + N' timedesc where tindex = @tindex and tddesc is not null order by tdline for xml raw)'
New Code:
set @mysql =
N'set @mystrmax =
(select tdline, LEFT(tddesc,CASE WHEN CHARINDEX(''^'',tddesc)=0 THEN LEN(tddesc) ELSE CHARINDEX(''^'',tddesc)-1 END) as tddesc
from ' + @timedesc + N' timedesc
where tindex = @tindex
and tddesc is not null
AND NOT EXISTS (SELECT * FROM timedesc caret WHERE timedesc.tindex=caret.tindex AND CHARINDEX(''^'',caret.tddesc)>0 AND timedesc.tdline>caret.tdline)
order by tdline for xml raw)'


No comments:
Post a Comment