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)
 Variable is being treated differently than literal

Author  Topic 

starkman
Starting Member

2 Posts

Posted - 2007-11-30 : 09:44:48
O.K. This is a weird one.... What am I missing?

--------------------------

DECLARE @EmailAddress VARCHAR
SET @EmailAddress = 'email@whatever.com'

SELECT
ID
FROM
EmailAddresses
WHERE
Address = @EmailAddress

--------------------------
Returns 0 rows... While...
--------------------------

SELECT
ID
FROM
EmailAddresses
WHERE
Address = 'email@whatever.com'

--------------------------
Returns rows.
--------------------------

So the question is Why is the variable not pulling results while the literal is?

Thanks!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-11-30 : 09:57:08
quote:
Originally posted by starkman

O.K. This is a weird one.... What am I missing?

--------------------------

DECLARE @EmailAddress VARCHAR(50)
SET @EmailAddress = 'email@whatever.com'

SELECT
ID
FROM
EmailAddresses
WHERE
Address = @EmailAddress

--------------------------
Returns 0 rows... While...
--------------------------

SELECT
ID
FROM
EmailAddresses
WHERE
Address = 'email@whatever.com'

--------------------------
Returns rows.
--------------------------

So the question is Why is the variable not pulling results while the literal is?

Thanks!




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

starkman
Starting Member

2 Posts

Posted - 2007-11-30 : 10:06:22
OK. So it was silly...

That was it. Thanks!
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-11-30 : 10:06:38
VARCHAR datatype defaults to 1 character if size is not specified.

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -