Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 compare a value in column

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-05-14 : 14:39:12
Hi there,

I need compare a value to a column in a table1:

table1
Id | Code |
01 | CCD
02 | FFT


How can I check if @varName is one of the values in column Code?

Thanks.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-14 : 14:55:18
quote:
Originally posted by allan8964

Hi there,

I need compare a value to a column in a table1:

table1
Id | Code |
01 | CCD
02 | FFT


How can I check if @varName is one of the values in column Code?

Thanks.

SELECT * FROM table1 WHERE Code = @varname
If you simply want a YES or NO answer:
IF EXISTS (SELECT * FROM table1 WHERE Code = @varname) 
SELECT 'Yes'
ELSE
SELECT 'No'
Go to Top of Page
   

- Advertisement -