这两个问题怎么解决?

seekmoon 2003-10-19 10:26:54
第一个:
自动获得用户输入的汉字的第一个字的收位拼音
比如输入“中国”,则在另外一个表中插入‘z’

第2个:数据库中记录为:
table 1:
id aID bID cID dID eID fID
0001 10 11 12 13 14 15
0002 32 33 34 35 36 37

table 2 结构如下
id content
10 aaaa
11 bbbb
12 cccc
.........
35 yyyy
36 9999
37 中国
.....
1009 公司内容


也就是说表table1中存放的都是id,真正的内容在table2中,现在要找出table1中的相关记录的完整信息,也就说最终返回如下结果
0001 aaaa bbbb cccc dddd jieguo haha ...
0002 asds afdff uyue yyyy 99999 中国。。。
怎么实现?
table1中的表字段名是不定的,也就是说还有table3、table4 的结构跟table1一样,只是字段名和字段数目不一样
...全文
30 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yujohny 2003-10-20
  • 打赏
  • 举报
回复
或者用这个
select id,B.content acontent,C.content Bcontent,
D.content Ccontent,E.content Dcontent,
F.content Econtent,G.content Fcontent
from table1 A left join table2 B on B.id=A.aid
left join table2 C on C.id=A.bid
left join table2 D on D.id=A.cid
left join table2 E on E.id=A.did
left join table2 F on F.id=A.eid
left join table2 G on G.id=A.fid
yujohny 2003-10-20
  • 打赏
  • 举报
回复
第二个问题:
select id,(select content from table2 where id=table1.aID) acontent,
(select content from table2 where id=table1.bID) bcontent,
(select content from table2 where id=table1.cID) ccontent,
(select content from table2 where id=table1.dID) dcontent,
(select content from table2 where id=table1.eID) econtent,
(select content from table2 where id=table1.fID) fcontent
from table1
seekmoon 2003-10-20
  • 打赏
  • 举报
回复
给点意见吧!!
welyngj 2003-10-19
  • 打赏
  • 举报
回复
1.answer:
--创建取拼音函数
create function fGetPy(@Str varchar(500)='')
returns varchar(500)
as
begin
declare @strlen int,@return varchar(500),@ii int
declare @n int,@c char(1),@chn nchar(1)

select @strlen=len(@str),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
select @n = @n +1
,@c = case chn when @chn then char(@n) else @c end
from(
select top 27 * from (
select chn = '吖'
union all select '八'
union all select '嚓'
union all select '咑'
union all select '妸'
union all select '发'
union all select '旮'
union all select '铪'
union all select '丌' --because have no 'i'
union all select '丌'
union all select '咔'
union all select '垃'
union all select '嘸'
union all select '拏'
union all select '噢'
union all select '妑'
union all select '七'
union all select '呥'
union all select '仨'
union all select '他'
union all select '屲' --no 'u'
union all select '屲' --no 'v'
union all select '屲'
union all select '夕'
union all select '丫'
union all select '帀'
union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
set @return=@return+@c
end
set @return=left(@return,1)
return(@return)
end

go
--测试
select dbo.fgetpy('东莞市') as 东莞市,dbo.fgetpy('中国人') as 中国人

--删除拼音函数

create table test1
( a1 char(10))
create table test2
(a2 char(10))
go
create trigger tri_test1_ins --触发器
on test1
for insert
as
begin
insert into test2 select dbo.fgetpy(a1) from test1
end
go
insert into test1 values('中国')
select * from test1
select * from test2
drop function fgetpy
seekmoon 2003-10-19
  • 打赏
  • 举报
回复
呵呵,谢谢你的关注!!

期待着大力进来看看
welyngj 2003-10-19
  • 打赏
  • 举报
回复
我没啧了
seekmoon 2003-10-19
  • 打赏
  • 举报
回复
这个函数很好,谢谢
请问对于第2个问题有没有方案?

还有,对于第一个问题,有没有可能返回完整的拼音,比如输入
‘中国’,然后函数返回‘zhongguo'?

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧