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

how to find if a variable is equal to a value in sql

I want to find if a variable has a particular value but i dont know the syntax, heres the sql code i have:

CREATE PROCEDURE usp_GetFilteredTimesheet
@clientID uniqueidentifier,
@ProjectID uniqueidentifier,
@employee nvarchar(50),
@Task nvarchar( 50)

IF @employee="MyValue" AND @Task ="MyValue"   BEGIN

SELECT Project FROM tbTimesheet

WHERE ProjectID=@ProjectID AND tblProject.ClientID =@ClientID

So I want to find if the value of the @employee and see if its value as a string is MyValue

I have hard coded the value in my c#.net  to be the string "MyValue"

This code doesnt work, i have a syntax error on : IF @employee="MyValue"

2 Solutions
Use ' instead of " around the varchar/string. "MyValue" -> 'MyValue'.
Pratima PharandeCommented:
use single quotes like this
IF @employee='MyValue' AND @Task ='MyValue'
CharlieDevAuthor Commented:
Thanks, i'm sure i had treid that it it didnt work, but i was wrong, tried again after the suggest and its worked, cheers
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

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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