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

Posted on 2008-11-06
Last Modified: 2010-04-21
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  to be the string "MyValue"

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

Question by:CharlieDev
    LVL 3

    Accepted Solution

    Use ' instead of " around the varchar/string. "MyValue" -> 'MyValue'.
    LVL 39

    Assisted Solution

    by:Pratima Pharande
    use single quotes like this
    IF @employee='MyValue' AND @Task ='MyValue'

    Author Closing Comment

    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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now