webForumDet fria alternativet

Uppdatera kolumn där jag hittar flera id'n...

Databaser & SQL

1 svar · 348 visningar · startad av CatZ

Medlem sedan jan. 20022 440 inlägg
Frågan#1
update ent_subscription
set ent_subscription  = convert(char(20),dateadd(yy,datediff(yy, ent_subscription, '2008-10-01 00:00:00.000'),ent_subscription),112 )
where ent_subscriptionid in 
	(
		select expdate.ent_subscriptionid
		from subscription s
			inner join ent_subscription cty on s.subscriptionid=cty.f_subscription
				and cty.f_type_ent_subscription=15

			inner join ent_subscription expdate on s.subscriptionid=expdate.f_subscription
				and expdate.f_type_ent_subscription=30

		where  cty.ent_subscription = '47' 
			and datediff(mm, expdate.ent_subscription, '2008-10-01') > 0
	)

Alltihop fungerar jättebra utom just att uppdatera. Hur kan jag uppdatera where id = något av id'na i min select statement? Om jag specificerar ett av id'na med

where ent_subscriptionid = 123123

så går det jättebra! *trött*

Medlem sedan dec. 20025 483 inlägg
#2

Vänta här nu... Om inte uppdateringen fungerar, vad är det då som går bra :p

update
    ent_subscription
set
    ent_subscription = convert(char(20),dateadd(yy,datediff(yy, expdate.ent_subscription, '2008-10-01 00:00:00.000'),expdate.ent_subscription),112 )
from
    subscription s inner join ent_subscription cty
    on
    s.subscriptionid = cty.f_subscription and
    cty.f_type_ent_subscription = 15
        inner join ent_subscription expdate 
        on 
        s.subscriptionid = expdate.f_subscription and 
        expdate.f_type_ent_subscription = 30
where
    cty.ent_subscription = '47' and 
    datediff(mm, expdate.ent_subscription, '2008-10-01') > 0
298 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
132 ms — deklarationer (db)
0 ms — hämta statistik (cache)
163 ms — hämta tråd, inlägg och bilagor (db)
120 ms — ändringar (db)