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
 General SQL Server Forums
 New to SQL Server Programming
 Simple Select statement problem

Author  Topic 

kilometres84
Starting Member

3 Posts

Posted - 2007-08-13 : 12:32:48
Hi,

I have several records in a table of "links", which has the fields ID, UserID, Description and URL. I'm trying to select all the records in this table for a specific user. The stored prodecure I'm using is:

ALTER PROCEDURE dbo.sprocLinkSelect (@UserID uniqueidentifier)

AS

SELECT ID, UserID, description, URL
FROM links
WHERE UserID = @UserID


When I execute the procedure without "UserID" in the SELECT part of the statement it works and returns the correct rows for the UserID entered as a parameter. However, when UserID is included in the SELECT part of the statement (as above), it says:

"No rows affected.
(1 row(s) returned)"

and just shows the column headings, but with no record details beneath. (When the example works as intended, it returns two rows.)

I've tried changing the procedure to take @description as its parameter and return all records with one specific description, and it also only works when UserID isn't included in the SELECT line. I've also tried using SELECT *, but that doesn't seem to work either.


Any help would be greatly appreciated, I'm using SQL Express.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-08-13 : 13:32:00
What data type is the UserID column in your table? I suspect it is not uniqueidentifier. Your parameter should be the same data type as the column you are comparing it to.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

kilometres84
Starting Member

3 Posts

Posted - 2007-08-13 : 18:07:00
UserID is a uniqueidentifier in the table, with allow nulls checked (as I'd like links to exist without a user assigned).
Go to Top of Page

kilometres84
Starting Member

3 Posts

Posted - 2007-08-13 : 18:12:07
The WHERE part actually seems to work, as when UserID isn't included in the SELECT part of the statement, the correct rows are found when I execute the procedure. It just doesn't seem to like having UserID in the SELECT part of the statement.
Go to Top of Page
   

- Advertisement -