?? procgetcomputermoneybiao.sql
字號:
Alter proc procGetComputerMoneyBiao
@XiaoQuName varchar(20),
@DongHao varchar(10),
@ShiHao varchar(10),
@Ellect varchar(20) output
As
Declare @intCountA int
Declare @price float
Declare @LeiChen int,@a int,@b int
Declare @JiaGe float
Declare @strFangXing varchar(20)
Declare @MianJi float,@MianJiYu float
-----------------------------------
Declare @BiaoDaShi varchar(2000)
Declare @BiaoDaShiOne varchar(2000),@XiangMu varchar(20),@BiaoDaShiTwo varchar(100)
Declare @intB int,@bLong int,@cLong int
Declare @DanWei varchar(20),@MoneyBiaoJuen float,@MoneyMi int
Declare @CountNum int --記錄的個數
Declare curFbwt cursor for --定義一個游標
Select 計算表達式,計算項目 from ComputerProject where 小區名稱=@XiaoQuName
Declare @XiangMuName varchar(20) --項目名稱
Select @a=count(*) from ShiHao where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao
if @a=0 --表明沒有這個記錄
Select @Ellect='沒有這個室號!'
if @a<>0
Begin
--計算基價
Select @LeiChen=樓層,@strFangXing=房型 from ShiHao where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao
--得到了樓的價格
--print '1 '+ @strFangXing
--print '2 '+ @LeiChen
Select @JiaGe=價格 from LeiJia where 小區名稱=@XiaoQuName and 樓層=@LeiChen
--得到面積
--print '3 '+ @JiaGe
Select @MianJi=實測總計面積,@MianJiYu=預測總計面積 from FangXing where 房型編號=@strFangXing
--print '4 '+ @MianJiYu
--print '5 '+ @MianJi
if @MianJi<1.0 --表明沒有實測總計面積
--采用預測總計面積
Begin
if @MianJiYu<1.0 --也沒有預測總計面積 出錯!
Select @Ellect='面積沒有輸入!'
if @MianJiYu>1.0 --用預測總計面積計算
select @price=@JiaGe * @MianJiYu
End
if @MianJI>1.0 --表明有實測總計面積
--采用實測總計面積計算
Begin
Select @price=@JiaGe * @MianJi
End
--基價加入MoneyList表中(費用列表)
Delete from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao
--查找是否已有當前項目的價格
Select @b=count(*) from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao and 項目名稱='基價'
if @b=0 --表明沒有當前項目價格
--加入新的
Begin
Insert into MoneyList(小區名稱,幢號,室號,項目名稱,金額) values(@XiaoQuName,@DongHao,@ShiHao,'基價',@price)
End
if @b<>0 --表明已有
Update MoneyList set 金額=@price where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@SHiHao and 項目名稱='基價'
--得到了基價
--清0
Select @price=0
----------------------------------------------------------------------------------
--從這兒開始得到別的費用項目
--得到表達式
Select @CountNum=count(*) from ComputerProject where 小區名稱=@XiaoQuName
Open curFbwt --打開游標
while @CountNum<>0
Begin
fetch next from curFbwt into @BiaoDaShi,@XiangMuName
while @@fetch_status=-1
break
select @CountNum=@CountNum-1
-- print @CountNum
--處理數據
--可能有好幾個記錄,下面的只能處理一條記錄
Select @cLong=len(@BiaoDaShi)
Select @BiaoDaShiOne=reverse(@BiaoDaShi)
Select @BiaoDaShiOne=rtrim(@BiaoDaShiOne)
Select @BiaoDaShiOne=ltrim(@BiaoDaShiOne)
Select @bLong=charindex('+',@BiaoDaShiOne)
Select @bLong=@bLong-1
while @cLong<>@bLong
Begin
--print '------------'
Select @BiaoDaShi=rtrim(@BiaoDaShi)
Select @BiaoDaShi=ltrim(@BiaoDaShi)
Select @cLong=len(@BiaoDaShi)
Select @intB=charindex('+',@BiaoDaShi)
Select @BiaoDaShiTwo=@BiaoDaShi
Select @BiaoDaShi=right(@BiaoDaShi,@cLong-@intB)
Select @intB=@intB-1
if @bLong=@cLong --表明是最后一個項目
Begin
--處理最后一項的MONEY
Select @MoneyBiaoJuen=收費標準,@DanWei=單位 from GetMoneyProject where 小區名稱=@XiaoQuName and 項目名稱=@BiaoDaShiTwo
--print '6 '+ @BiaoDaShiTwo
Goto fbwtComputerMoney
End
--處理前幾項
Select @XiangMu=left(@BiaoDaShiTwo,@intB)
--Select @intCountA=count(*) from GetMoneyProject where 小區名稱=@XiaoQuName and 項目名稱=@XiangMu
--if @intCountA=0 --表明收費項目設置中沒有這一項,可能是因為刪除引起的
--在當前操作表中刪除這一項
--Begin
--Delete from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao and 項目名稱=@XiangMu
--Continue
--End
Select @MoneyBiaoJuen=收費標準,@DanWei=單位 from GetMoneyProject where 小區名稱=@XiaoQuName and 項目名稱=@XiangMu
--print '7 '+ @XiangMu
fbwtComputerMoney:
if @MianJi<1 --表明沒有實測總計面積
--采用預測總計面積
Begin
select @MoneyMi=0
Select @MoneyMi=charindex('M',@DanWei)
if @MoneyMi<>0 --表明有面積的加入計算
select @price=@MianJiYu * @MoneyBiaoJuen
End
if @MianJI>1 --表明有實測總計面積
--采用實測總計面積計算
Begin
select @MoneyMi=0
Select @MoneyMi=charindex('M',@DanWei)
if @MoneyMi<>0 --表明有面積的加入計算
select @price=@MianJi * @MoneyBiaoJuen+@price
if @MoneyMi=0--表明沒有面積的加入計算
select @price=@MOneyBiaoJuen+@price
--print @DanWei
--print '??????'
--print @MoneyMi
--print '>>>>>>>>>>>>>>>>>>>>>'
--print @MianJI
--print '!!!!!!!!!!'
--print @MoneyBiaoJuen
--print '<<<<<<<<<<<<<<<<<<<<'
--print @price
End
--print '8 '+ @price
End
---------------------加入到MoneyList表中, 要用到項目名稱
Select @b=count(*) from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao and 項目名稱=@XiangMuName
if @b=0 --表明沒有當前項目價格
--加入新的
Begin
Insert into MoneyList(小區名稱,幢號,室號,項目名稱,金額) values(@XiaoQuName,@DongHao,@ShiHao,@XiangMuName,@price)
End
if @b<>0 --表明已有
Update MoneyList set 金額=@price where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@SHiHao and 項目名稱=@XiangMuName
--print '9 '+@XiangMuName
Select @price=0
End
Deallocate curFbwt --放游標
Select @price=0
Select @price=sum(金額) from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao
Select @b=count(*) from MoneyList where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@ShiHao and 項目名稱='總價'
if @b=0 --表明沒有當前項目價格
--加入新的
Begin
Insert into MoneyList(小區名稱,幢號,室號,項目名稱,金額) values(@XiaoQuName,@DongHao,@ShiHao,'總價',@price)
End
if @b<>0 --表明已有
Update MoneyList set 金額=@price where 小區名稱=@XiaoQuName and 幢號=@DongHao and 室號=@SHiHao and 項目名稱=@XiangMuName
--print '9 '+@XiangMuName
select @Ellect='成功'
End
Go
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -