Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,
This is my codition what i want
when @var='Pending' then field is null
when @var='Lotwise' then field=field
when @var='Canceled' then Canflag(another field)=1

Please give me solution for that.

What I have tried:

This what i did
Declare @status varchar(10);
set @status='Pending'
select EntryNo,entryDt,EntryLMBY,convert(date,EntryLMDT,106)EntryLMDT,LOtNo_Site2HO,Cancelflag  from dbo.tbl_Activity
where
CASE @status 
WHEN 'Pending' THEN LOtNo_Site2HO IS NULL
WHEN 'LotWise' THEN LOtNo_Site2HO=LOtNo_Site2HO
WHEN 'Canceld' THEN CANCELFLAG=1
end
Posted
Updated 3-Jan-18 18:55pm

1 solution

you shall try this

Declare @status varchar(10);
set @status='pending'

declare @query varchar(500)
declare @where varchar(100)
set @query  = 'select EntryNo,entryDt,EntryLMBY,convert(date,EntryLMDT,106)EntryLMDT,LOtNo_Site2HO,Cancelflag  from dbo.tbl_Activity where '
select  @where =    case @status
				    when 'pending' then ' LOtNo_Site2HO IS NULL '
					WHEN 'LotWise' THEN ' LOtNo_Site2HO=LOtNo_Site2HO '
					WHEN 'Canceld' THEN ' CANCELFLAG=1 '
					 else ' 1=1 ' 
					end 

set @query = @query + @where 
print @query
--exec(@query)
 
Share this answer
 
Comments
SujataJK 4-Jan-18 1:07am    
THANKS Sir.
Karthik_Mahalingam 4-Jan-18 1:12am    
welcome

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