开发者

Msg 4104, Level 16, State 1, Procedure cst_priceimporter, Line 37

I have written the following code and getting the below error, I believe its to do with how I am joining to the country table but can't work out how to fix. Can anyone point me in the right direction please

Msg 4104, Level 16, State 1, Procedure cst_priceimporter, Line 37
The multi-part identifier "country.price" could not be bound.

 

create procedure cst_priceimporter as



declare @todayDt datetime
declare @dtfirst int
declare @dtweek int 
declare @iswkday bit 


select @todayDt = convert(varchar,getdate(),101)

set @dtfirst = @@datefirst - 1
set @dtweek = datepart(weekday, @todayDt) -1



if (@dtfirst + @dtweek) % 7 = 0
    begin   


        set @todaydt = @todaydt- 2

        update  SecPriceHist
        set     fxrate = 1 / fxrate
        from    SecPriceHist sph
        join    sec s
        on      sph.id = s.id
        and     sph.priceSource = 'DFLT' 
        and     sph.hdate = @todayDt 
        and     sph.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     sph.id <> 'SEK'

        update  country 
        set     country.price = 1 / country.price
        from    country c
        join    sec s
        on      s.country = c.country
        and     s.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     s.id <> 'SEK'
        join    secpricehist sph
        on      sph.id = s.id
        and     s.country = c.country
        and     sph.priceSource = 'DFLT' 
        and     sph.hdate = @todayDt 
        and     sph.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     sph.id <> 'SEK' 






    end
else
        set @todaydt = @todaydt- 1

        update  SecPriceHist
        set     fxrate = 1 / fxrate
        from    SecPriceHist sph
        join    sec s
        on      sph.id = s.id
        and     sph.priceSource = 'DFLT' 
        and     sph.hdate = @todayD开发者_运维问答t 
        and     sph.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     sph.id <> 'SEK'


        update  country 
        set     country.price = 1 / country.price
        from    country c
        join    sec s
        on      s.country = c.country
        and     s.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     s.id <> 'SEK'
        join    secpricehist sph
        on      sph.id = s.id
        and     s.country = c.country
        and     sph.priceSource = 'DFLT' 
        and     sph.hdate = @todayDt 
        and     sph.dateStamp between DATEADD(mi,-1,getdate()) and getdate()
        and     s.sectype <2 and s.country not in ('SupraNational','ZMultiCountry')
        and     sph.id <> 'SEK' 


The SET part of update should NOT have any table name, you can only update one anyway. Also since you have aliased Country as C, you need to use the alias

update  country 
set     price = 1 / c.price

I think it occurs twice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜