--to 楼上:不行. --我写了一下测试数据, 楼下高人作答吧. --测试数据 create table gyfz_news(title varchar(100)) insert gyfz_news select '300%高额利润使降价遭拒 上海开发商联手挺' union all select '贵阳市商品房预售款使用监督管理暂行规定规定' union all select '上海市《关于商品房销售合同网上备案和登记有关 ' union all select '厦门市商品房销售合同网上登记备案管理办法管理' --查询 select left(title, 10), datalength(left(title, 10)) from gyfz_news --清除 drop table gyfz_news
用 select convert(char(20),title) 试试
SELECT cast(LTRIM(title) as char(38)) as title FROM gyfz_news
--创建函数 if object_id('getstr') is not null drop function getstr go create function getstr ( @str varchar(2000) ) returns varchar(50) as begin declare @tmp varchar(50) set @tmp='' while datalength(@tmp)<=20 begin set @tmp=@tmp+left(@str,1) set @str=stuff(@str,1,1,'') end return @tmp end--测试 create table gyfz_news(title varchar(100)) insert gyfz_news select '300%高额利润使降价遭拒 上海开发商联手挺' union all select '贵阳市商品房预售款使用监督管理暂行规定规定' union all select '上海市《关于商品房销售合同网上备案和登记有关 ' union all select '厦门市商品房销售合同网上登记备案管理办法管理' --查询 select dbo.getstr(title) from gyfz_news --清除 drop table gyfz_news--结果 /*
--我写了一下测试数据, 楼下高人作答吧.
--测试数据
create table gyfz_news(title varchar(100))
insert gyfz_news select '300%高额利润使降价遭拒 上海开发商联手挺'
union all select '贵阳市商品房预售款使用监督管理暂行规定规定'
union all select '上海市《关于商品房销售合同网上备案和登记有关 '
union all select '厦门市商品房销售合同网上登记备案管理办法管理'
--查询
select left(title, 10), datalength(left(title, 10))
from gyfz_news
--清除
drop table gyfz_news
if object_id('getstr') is not null
drop function getstr
go
create function getstr
(
@str varchar(2000)
)
returns varchar(50)
as
begin
declare @tmp varchar(50)
set @tmp=''
while datalength(@tmp)<=20
begin
set @tmp=@tmp+left(@str,1)
set @str=stuff(@str,1,1,'')
end return @tmp
end--测试
create table gyfz_news(title varchar(100))
insert gyfz_news select '300%高额利润使降价遭拒 上海开发商联手挺'
union all select '贵阳市商品房预售款使用监督管理暂行规定规定'
union all select '上海市《关于商品房销售合同网上备案和登记有关 '
union all select '厦门市商品房销售合同网上登记备案管理办法管理'
--查询
select dbo.getstr(title)
from gyfz_news
--清除
drop table gyfz_news--结果
/*
--------------------------------------------------
300%高额利润使降价遭拒
贵阳市商品房预售款使用
上海市《关于商品房销售
厦门市商品房销售合同网(所影响的行数为 4 行)
*/