D
Dan M
Can't get my stored procedure to return the value I want.
When I hard code the criteria of the WHERE statement, all
is fine. When I use a variable, it returns nothing.
The Sproc looks like this:
DECLARE @theUser nvarchar(12)
SET @theUser = suser_sname()
SELECT UserRegion FROM tblCurrentUserSettings WHERE UserID
= @theUser
If I use this SELECT statement, replacing the variable
with a hard coded value, it works:
SELECT UserRegion FROM tblCurrentUserSettings WHERE UserID
= 'cti/mccleldr'
I test the value of @theUser, and it returns cti/mccleldr
I assume maybe the datatype of the suser_sname() function
is the problem, so I added another variable and tried:
SET @theUserConverted = Cast(@theUser AS nvarchar(12))
This new variable returns the same value I need, but still
doesn't work in the SELECT statement.
I even tried using a string variable to concatenate the
SELECT statement, it still returns nothing.
SET @mySQL = "SELECT UserRegion FROM
tblCurrentUserSettings WHERE UserID = " + @theUser
Exec (@mySQL)
I've tried everything I can think of. Each step works
properly by itself, but putting the steps together will
never return the value I need. Auuugh. Help.
When I hard code the criteria of the WHERE statement, all
is fine. When I use a variable, it returns nothing.
The Sproc looks like this:
DECLARE @theUser nvarchar(12)
SET @theUser = suser_sname()
SELECT UserRegion FROM tblCurrentUserSettings WHERE UserID
= @theUser
If I use this SELECT statement, replacing the variable
with a hard coded value, it works:
SELECT UserRegion FROM tblCurrentUserSettings WHERE UserID
= 'cti/mccleldr'
I test the value of @theUser, and it returns cti/mccleldr
I assume maybe the datatype of the suser_sname() function
is the problem, so I added another variable and tried:
SET @theUserConverted = Cast(@theUser AS nvarchar(12))
This new variable returns the same value I need, but still
doesn't work in the SELECT statement.
I even tried using a string variable to concatenate the
SELECT statement, it still returns nothing.
SET @mySQL = "SELECT UserRegion FROM
tblCurrentUserSettings WHERE UserID = " + @theUser
Exec (@mySQL)
I've tried everything I can think of. Each step works
properly by itself, but putting the steps together will
never return the value I need. Auuugh. Help.