0

Hi...

I want to write a IF Condition as follow:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[abc]          
AS 
SET NOCOUNT ON;            
BEGIN      

Declare @add = 0 as int
Declare @change = 0 as int
Declare @remove = 0 as int

Select  abc.value as 'Name'
           if (History.OLDSTR == '' and History.NEWSTR == [B]value[/B]) then 
           add++ as [Add]

from History INNER JOIN MetaObjAttrRelations
		ON History.MetaObjAttrRelations_Idn = METAOBJATTRRELATIONS.METAOBJATTRRELATIONS_IDN

End

In the above code value is present in the database. So how to write that column name in place of value. Im trying to create a procedure where there is old value and new value. If the old value has change or modified then change variable will increment by 1, if there is no old value in the database and i have added new value in the databse then add variable will increment by 1, if there is value in the old value and i have deleted the old value, then remove variable will increment by 1.

So kindly help me out to solve this issueee...

Edited by Ezzaral: Added [code] [/code] tags. Please use them to format any code that you post.

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Abhishek_Boga
0

If statements can not be used within a select statement. Not quite sure what you are trying to achieve here but you could sum a case statement to increment a value.

Select  abc.value as 'Name',
sum(case when (History.OLDSTR == '' and History.NEWSTR == value) then 1 else 0 end) [Add]
From History INNER JOIN MetaObjAttrRelations
		ON History.MetaObjAttrRelations_Idn = METAOBJATTRRELATIONS.METAOBJATTRRELATIONS_IDN

Edited by cgyrob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.