sql如下:
insert into House(ClientHouseID,DistrictName,EstateName,BuildName,RoomNo,ContactInfo,Re)
if(charindex('楼',Col005) = 3)
begin
select 'spirit','东城','康乐花园(景湖春晓)',substring(Col005,1,charindex('楼',Col005)) as BuildName,
substring(Col005,charindex('楼',Col005)+1,9) RoomNo,Col005+' '+Col003 as ContactInfo,
'春晓A(每日签约总表)' as Re
from [春晓A(每日签约总表)]
end
else if(charindex('座',Col005)=3)
begin
select 'spirit','东城','康乐花园(景湖春晓)',substring(Col005,1,charindex('座',Col005)) as BuildName,
substring(Col005,charindex('座',Col005)+1,9) RoomNo,Col005+' '+Col003 as ContactInfo,
'春晓A(每日签约总表)' as Re
from [春晓A(每日签约总表)]
end请问,这样做可行吗?我想一次性实现
House表 春晓
Buildname RoomNo Col005
12座 A梯1101 12座A梯1101
11楼 B梯1105 11楼B梯1105
拜托各位哥哥姐姐了,嘿嘿!!
insert into House(ClientHouseID,DistrictName,EstateName,BuildName,RoomNo,ContactInfo,Re)
if(charindex('楼',Col005) = 3)
begin
select 'spirit','东城','康乐花园(景湖春晓)',substring(Col005,1,charindex('楼',Col005)) as BuildName,
substring(Col005,charindex('楼',Col005)+1,9) RoomNo,Col005+' '+Col003 as ContactInfo,
'春晓A(每日签约总表)' as Re
from [春晓A(每日签约总表)]
end
else if(charindex('座',Col005)=3)
begin
select 'spirit','东城','康乐花园(景湖春晓)',substring(Col005,1,charindex('座',Col005)) as BuildName,
substring(Col005,charindex('座',Col005)+1,9) RoomNo,Col005+' '+Col003 as ContactInfo,
'春晓A(每日签约总表)' as Re
from [春晓A(每日签约总表)]
end请问,这样做可行吗?我想一次性实现
House表 春晓
Buildname RoomNo Col005
12座 A梯1101 12座A梯1101
11楼 B梯1105 11楼B梯1105
拜托各位哥哥姐姐了,嘿嘿!!
insert into 表 (字段1,...) select * from ...
union all select * from
select 'spirit','东城','康乐花园(景湖春晓)',left(Col005,3),substring(Col005,4,9),Col005+' '+Col003,'春晓A(每日签约总表)'
from [春晓A(每日签约总表)]
where substring(Col005,3,1) in ('楼','座')
insert into 后面不能跟着if 语句象你上面的语句,适合使用 case when .... then ...else ...endinsert into House(ClientHouseID,DistrictName,EstateName,BuildName,RoomNo,ContactInfo,Re)
select 'spirit','东城','康乐花园(景湖春晓)',
case when charindex('楼',Col005) = 3 then substring(Col005,1,charindex('楼',Col005)) else null ende,
,substring(Col005,charindex('楼',Col005)+1,9) RoomNo --还有这名
,Col005+' '+Col003 as ContactInfo, '春晓A(每日签约总表)' as Re
from [春晓A(每日签约总表)]