--> 测试数据: [石头表] if object_id('[石头表]') is not null drop table [石头表] create table [石头表] (id int,名称 varchar(4),备注 varchar(4),图片路径 varchar(500)) insert into [石头表] select 5,'石头','很好','<P><IMG src="/hkcdhx/edit/UploadFile/201053021530476.jpg" border=0></P> <P><FONT face=Verdana>从上往下拍</FONT></P> <P><IMG src="/hkcdhx/edit/UploadFile/2010530215311474.jpg" border=0></P> <P><FONT face=Verdana>从左往右拍</FONT></P>' go--> 测试数据: [图片表] if object_id('[图片表]') is not null drop table [图片表] create table [图片表] (id int identity(1,1), 对应表名 varchar(6),对应记录id int,图片路径 varchar(100)) go--操作 with wsp as ( select a.*,px=row_number()over(order by getdate()),substring(图片路径+'"',number,charindex('"',图片路径+'"',number+1)-number) X from [石头表] a,master..spt_values b where substring('"'+图片路径,b.number,1)='"' and b.type='p' ) insert into 图片表(对应表名,对应记录id,图片路径) select '石头表',b.id,b.x from wsp a,wsp b where right(a.x,4)='src=' and b.px=a.px+1--测试: select * from 图片表--结果: id 对应表名 对应记录id 图片路径 ----------- ------ ----------- ---------------------------------------------------------------------------------------------------- 1 石头表 5 /hkcdhx/edit/UploadFile/201053021530476.jpg 2 石头表 5 /hkcdhx/edit/UploadFile/2010530215311474.jpg
好专业哦。。我的SQL 都快忘记完了。。
--若查询石头的图片则语句为:,并获取路径select *from 图片表 a join 石头表 b on a.对应记录id=b.id WHERE a.id='石头表' --若查询瓷器的图片则语句为:,并获取路径 select *from 图片表 a join 瓷器表 b on a.对应记录id=b.id WHERE a.id='瓷器表' 。
--> 测试数据: [石头表] if object_id('[石头表]') is not null drop table [石头表] create table [石头表] (id int,名称 varchar(4),备注 varchar(4),图片路径 varchar(500)) insert into [石头表] select 5,'石头','很好','<P><IMG src="/hkcdhx/edit/UploadFile/201053021530476.jpg" border=0></P> <P><FONT face=Verdana>从上往下拍</FONT></P> <P><IMG src="/hkcdhx/edit/UploadFile/2010530215311474.jpg" border=0></P> <P><FONT face=Verdana>从左往右拍</FONT></P>' go--> 测试数据: [图片表] if object_id('[图片表]') is not null drop table [图片表] create table [图片表] (id int identity(1,1), 对应表名 varchar(6),对应记录id int,图片路径 varchar(100),描述 varchar(100)) go--操作 with wsp as ( select a.*,px=row_number()over(order by getdate()),substring(图片路径+'"',number,charindex('"',图片路径+'"',number+1)-number) X from [石头表] a,master..spt_values b where substring('"'+图片路径,b.number,1)='"' and b.type='p' ) insert into 图片表(对应表名,对应记录id,图片路径,描述) select '石头表',b.id,b.x,substring(c.x,charindex('<FONT face=Verdana>',c.x)+len('<FONT face=Verdana>'),charindex('</FONT>',c.x)-(charindex('<FONT face=Verdana>',c.x)+len('<FONT face=Verdana>'))) from wsp a,wsp b,wsp c where right(a.x,4)='src=' and b.px=a.px+1 and c.px=b.px+1--测试: select * from 图片表--结果:id 对应表名 对应记录id 图片路径 描述 ----------- ------ ----------- ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- 1 石头表 5 /hkcdhx/edit/UploadFile/201053021530476.jpg 从上往下拍 2 石头表 5 /hkcdhx/edit/UploadFile/2010530215311474.jpg 从左往右拍
图片表
id 对应表名 对应记录id 图片路径 备注
1 石头表 5 /hkcdhx/edit/UploadFile/201053021530476.jpg 从上往下拍
2 石头表 5 /hkcdhx/edit/UploadFile/2010530215311474.jpg 从左往右拍
石头表
id 名称 备注
1 石头 很好这里应该把1改成5.
图片有主健,就是id.
对应表名我有用,因为有很多的表,除了石头表还有瓷器表等等。我是所有表的图片都放在图片表里面,以
对应表名 对应记录id 两个字段对应。
if object_id('[石头表]') is not null drop table [石头表]
create table [石头表] (id int,名称 varchar(4),备注 varchar(4),图片路径 varchar(500))
insert into [石头表]
select 5,'石头','很好','<P><IMG src="/hkcdhx/edit/UploadFile/201053021530476.jpg" border=0></P> <P><FONT face=Verdana>从上往下拍</FONT></P> <P><IMG src="/hkcdhx/edit/UploadFile/2010530215311474.jpg" border=0></P> <P><FONT face=Verdana>从左往右拍</FONT></P>'
go--> 测试数据: [图片表]
if object_id('[图片表]') is not null drop table [图片表]
create table [图片表] (id int identity(1,1), 对应表名 varchar(6),对应记录id int,图片路径 varchar(100))
go--操作
with wsp
as
(
select a.*,px=row_number()over(order by getdate()),substring(图片路径+'"',number,charindex('"',图片路径+'"',number+1)-number) X
from [石头表] a,master..spt_values b
where substring('"'+图片路径,b.number,1)='"' and b.type='p'
)
insert into 图片表(对应表名,对应记录id,图片路径) select '石头表',b.id,b.x from wsp a,wsp b where right(a.x,4)='src=' and b.px=a.px+1--测试:
select * from 图片表--结果:
id 对应表名 对应记录id 图片路径
----------- ------ ----------- ----------------------------------------------------------------------------------------------------
1 石头表 5 /hkcdhx/edit/UploadFile/201053021530476.jpg
2 石头表 5 /hkcdhx/edit/UploadFile/2010530215311474.jpg
WHERE a.id='石头表'
--若查询瓷器的图片则语句为:,并获取路径
select *from 图片表 a join 瓷器表 b on a.对应记录id=b.id
WHERE a.id='瓷器表'
。
--> 测试数据: [石头表]
if object_id('[石头表]') is not null drop table [石头表]
create table [石头表] (id int,名称 varchar(4),备注 varchar(4),图片路径 varchar(500))
insert into [石头表]
select 5,'石头','很好','<P><IMG src="/hkcdhx/edit/UploadFile/201053021530476.jpg" border=0></P> <P><FONT face=Verdana>从上往下拍</FONT></P> <P><IMG src="/hkcdhx/edit/UploadFile/2010530215311474.jpg" border=0></P> <P><FONT face=Verdana>从左往右拍</FONT></P>'
go--> 测试数据: [图片表]
if object_id('[图片表]') is not null drop table [图片表]
create table [图片表] (id int identity(1,1), 对应表名 varchar(6),对应记录id int,图片路径 varchar(100),描述 varchar(100))
go--操作
with wsp
as
(
select a.*,px=row_number()over(order by getdate()),substring(图片路径+'"',number,charindex('"',图片路径+'"',number+1)-number) X
from [石头表] a,master..spt_values b
where substring('"'+图片路径,b.number,1)='"' and b.type='p'
)
insert into 图片表(对应表名,对应记录id,图片路径,描述)
select '石头表',b.id,b.x,substring(c.x,charindex('<FONT face=Verdana>',c.x)+len('<FONT face=Verdana>'),charindex('</FONT>',c.x)-(charindex('<FONT face=Verdana>',c.x)+len('<FONT face=Verdana>')))
from wsp a,wsp b,wsp c where right(a.x,4)='src=' and b.px=a.px+1 and c.px=b.px+1--测试:
select * from 图片表--结果:id 对应表名 对应记录id 图片路径 描述
----------- ------ ----------- ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
1 石头表 5 /hkcdhx/edit/UploadFile/201053021530476.jpg 从上往下拍
2 石头表 5 /hkcdhx/edit/UploadFile/2010530215311474.jpg 从左往右拍