Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have the following SQL statement. I want to check whether the returned value contain 1. How can I do it? Any help would be appreciated. Below are my codes:


SQL
SELECT pd.IsSerialNumberMaskRequired from ProductSetup.ProductVersion as pv
INNER join ProductSetup.ProductDetail as pd
on pv.ProductHeaderId = pd.ProductHeaderId
where pv.ProductVersionId = '24127'


The above SQL statement return 4 rows of records with the value 1, 1, 0, 1 for each row.
It has 3 "1", how can I determine it?
Posted

try something like this:
SQL
SELECT count(pd.IsSerialNumberMaskRequired) from ProductSetup.ProductVersion as pv
INNER join ProductSetup.ProductDetail as pd
on pv.ProductHeaderId = pd.ProductHeaderId
where pv.ProductVersionId = '24127' and pd.IsSerialNumberMaskRequired = 1
group by pd.IsSerialNumberMaskRequired


Good luck!
 
Share this answer
 
v2
Comments
Jamie888 23-Feb-15 20:53pm    
Yes thank you. I have add on some SQL codes to return the result I desired. Please have a look and feel free to comment on any improvement that is needed thank you.
SQL
declare @counts int = 0

set @counts = (SELECT count(pd.IsSerialNumberMaskRequired) from ProductSetup.ProductVersion as pv
INNER join ProductSetup.ProductDetail as pd
on pv.ProductHeaderId = pd.ProductHeaderId
where pv.ProductVersionId = '24127' and pd.IsSerialNumberMaskRequired = 1
group by pd.IsSerialNumberMaskRequired)


IF @counts > 0
select 1
 
Share this answer
 
v2
Comments
King Fisher 23-Feb-15 23:34pm    
You must accept the above answer.you can't get it without him.you just modified .!!

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