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...

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

Thankx dear... It worked out..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.