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.
Author |
Topic |
DURGESH
Posting Yak Master
105 Posts |
Posted - 2008-06-18 : 07:04:52
|
HI ALLCAN ANYBODY HELP ME TO SOLVE THE FOLLOWING PROBLEMHOW TO THE COMPARE THE VALUE OF A VARIABLE WITH THE VALUES FROM A COLUMN OF A TABLEEXAMPLE@VAR='SANIA'TABLEA(ID,NAME)TABLEAID NAME1 ABC2 XYZ3 SANIANOW I WANT TO CHECK WHETHER THE VALUE SET IN @VAR IS AVAILABLE IN THE NAME COLUMN OR NOTI WROTE THE QUERY IF(@VAR IN (SELECT NAME FROM TABLEA))SELECT 'AVAILABLE'ELSESELECT 'N/A'IS MY QUERY IS CORRECT OR NOT THANKS IN ADVANCE |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-06-18 : 07:32:52
|
Do you mean as in select <fieldlist> from table where <field> = @variable ? |
 |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-06-19 : 01:31:10
|
Why not run it and see if it works correctly? |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-06-19 : 02:12:57
|
also, take that brick off the CAPS LOCK KEY. elsasoft.org |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 03:03:24
|
or this:-IF (SELECT COUNT(*) FROM TABLEA WHERE NAME=@VAR) >0SELECT 'AVAILABLE'ELSESELECT 'N/A' |
 |
|
|
|
|