Click here to Skip to main content
15,889,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
if EXISTs(SELECT 1 FROM Framework.Service WHERE ID = 'B0ED76DD-F93B-4B64-8E87-654129E2A8AC' AND DeploymentID = 'D6726F6A-10A0-4917-AFD3-21949A62CD51')
begin
--print 'x'
Update Custom.Membership
set membershiptype = 'Unlimited/Ongoing' where Ongoing = 1
end


Here condition is false still it tries to set membershiptype column which does not exists and throws the error.
Posted
Updated 22-May-14 22:44pm
v2

See with else part then you can get the point where it is missing if condition in your nested query
IF EXISTS(SELECT * FROM Framework.Service WHERE ID = 'B0ED76DD-F93B-4B64-8E87-654129E2A8AC' AND DeploymentID = 'D6726F6A-10A0-4917-AFD3-21949A62CD51')
begin
	--check whether ma package is not installed
	IF NOT EXISTS(SELECT * FROM Framework.Service WHERE ID = '764AE521-320E-4B90-A9F7-5C7614C5C28E' AND DeploymentID = '3015C5DB-DE04-4B73-89BF-AEDE95F3D9F8')
	begin 
		if exists (select * from [Framework].[Object] where id = '8AC96BD2-9550-486B-804E-A40D0C57D6EC')
		begin --go
			Update Custom.Membership
			set membershiptype = 'Unlimited/Ongoing' where Ongoing = 1
		end
		else begin
			select 'else part of last nested if'
		end
	end
		else begin
			select 'else part of second nested if'
		end
end
else begin
	select 'else part of first nested if'
end
 
Share this answer
 
Comments
Peeyush Pachaori 23-May-14 4:42am    
if EXISTs(SELECT 1 FROM Framework.Service WHERE ID = 'B0ED76DD-F93B-4B64-8E87-654129E2A8AC' AND DeploymentID = 'D6726F6A-10A0-4917-AFD3-21949A62CD51')
begin
--print 'x'
Update Custom.Membership
set membershiptype = 'Unlimited/Ongoing' where Ongoing = 1
end

Here condition is false still it tries to set membershiptype column which does not exists and throws the error.
I got the solution-
In this case I have to use dynamic sql.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900