I am trying to run below code in SQL server 2000 SP4 but getting error.
Declare @Body varchar(8000);
Declare @TableHead varchar(8000);
Declare @TableTail varchar(8000);
Set NoCount On;
Set @TableTail = '</table></body></html>';
Set @TableHead = '<html><head>' +
'<style>
td {border: solid black 1px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:11pt;}
tr.even {background-color:white;}
tr.odd {background-color:#eeeeee;}
</style>' +
'</head>' +
'<body><table cellpadding=0 cellspacing=0 border=0>' +
'<tr bgcolor=#FFEFD8><td align=center><b>Server Name</b></td>' +
'<td align=center><b>Product</b></td>' +
'<td align=center><b>Provider</b></td>' +
'<td align=center><b>Data Source</b></td>' +
'<td align=center><b>Is Linked?</b></td></tr>';
Select @Body = (Select
name As [TD],
product As [TD],
provider As [TD],
data_source As [TD align=center],
is_linked As [TD align=center]
From sys.servers
Order By is_linked, name
For XML Raw('tr'), Elements);
Set @Body = Replace(@Body, '_x003D_', '=');
Set @Body = Replace(@Body, '_x0020_', space(1));
Select @TableHead + @Body + @TableTail;
Error:
Msg 156, Level 15, State 1
Incorrect syntax near the keyword 'For'.
I took this code from here:
and am using it as a reference to build a new report. I have a mix of SQL Server 2000, 2005, 2008, 2012 instances in my environment. This code works on other servers but not in 2000 SP4.
Please help me fix this.