• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Check to see if values exist

How do I check to see if the value "25" exists or not in a column named "Product"?  
0
johnqtr
Asked:
johnqtr
  • 2
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
SELECT Count(Product)
FROM YourTable
WHERE Product = 25

(if Product is text)
WHERE Product = '25'

@@ROWCOUNT will now have the number of records in the above query, so you can test it.

Hope this helps.
-Jim
0
 
rafranciscoCommented:
SELECT * FROM YourTable
WHERE Product = 25

or

SELECT 'Product 25 Exists' FROM YourTable
WHERE EXISTS (SELECT 'X' FROM YourTable
                        WHERE Product = 25)
0
 
rafranciscoCommented:
SELECT 'Product 25 Exists'
WHERE EXISTS (SELECT 'X' FROM YourTable
                        WHERE Product = 25)
0
 
adatheladCommented:
IF EXISTS(SELECT 1 FROM TableName WHERE Product = 25)
    -- Product exists so do something...
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks.  IMO rafrancisco and adathelad's comments are equally workable...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now