1.<br>select * from TableName where Field1='X%' order by Field1<br>union<br>select * from TableName where Field1!='X%' order by Field1<br>错误: union 子句不允许有 order by<br><br>2.正确:<br>CREATE function GetXto0<br>(@Version char(10))<br>returns char(10)<br>as<br>begin<br> declare @result char(10)<br> if charindex('X',@Version)=0<br> set @result=@Version<br> else <br> set @result=stuff(@Version,charindex('X',@Version),1,'0')<br> return <br> @result<br>end<br>错误:if charindex('X',@Version)=NULL -- 应该是<br> if charindex('X',@Version)=0