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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Check variable

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-02-14 : 06:40:30
Hello,

I have the following code:

DECLARE @LevelId UNIQUEIDENTIFIER
SELECT @LevelId = LevelId FROM dbo.Levels WHERE LevelName = @LevelName

Later in my code I need to check if a record was found or not.

How can I do this?

I know I could do:
EXISTS(SELECT @LevelId = LevelId FROM dbo.Levels WHERE LevelName = @LevelName)

But I don't want to do this. I want to check the @LevelId variable.

Thanks,
Miguel

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-14 : 06:44:14
Assuming LevelID does not contain NULLS, you can do this,

If @LevelId IS Not NULL
-- record found do something
Else
-- record not found, do something



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -