all groups > sql server programming > august 2004 >
You're in the

sql server programming

group:

SQL don't like the subquery


Re: SQL don't like the subquery David Portas
8/31/2004 8:20:39 PM
sql server programming:
A fragment of code like this doesn't give us much to go on. At a guess, I'd
say that sUserID isn't unique in the table tblUsersMemberKundTjanster, which
would explain the error message "Subquery returned more than 1 value". If
you need more help: http://www.aspfaq.com/5006

--
David Portas
SQL Server MVP
--

Re: SQL don't like the subquery David Portas
8/31/2004 9:11:09 PM
[quoted text, click to view]

You can't rely on that. It depends on the execution order of the predicates,
which you can't control. Try this:

....
WHERE tblTjanster.iKundID = @iKundID
AND tblTjanster.iHsID = @iHsID
AND tblTjanster.btAvslutad = @btAvslutad
AND (tblTjanster.iKundTjanstID IN
(SELECT iKundTjanstID
FROM tblUsersMemberKundTjanster
WHERE sUserID = @sUserID
AND @iKundTjanstID = 1)
OR tblTjanster.iKundTjanstID = @iKundTjanstID)
AND tblTjanster.blKasserad = 0
AND tblTjanster.iUppehallID = 0

--
David Portas
SQL Server MVP
--

SQL don't like the subquery Kenneth
8/31/2004 9:14:16 PM
WHERE (tblTjanster.iKundID = @iKundID)

AND (tblTjanster.iHsID = @iHsID)

AND (tblTjanster.btAvslutad = @btAvslutad)

AND tblTjanster.iKundTjanstID IN (CASE WHEN @iKundTjanstID = 1 THEN (SELECT
iKundTjanstID FROM tblUsersMemberKundTjanster WHERE sUserID = @sUserID)ELSE
@iKundTjanstID END)

AND (tblTjanster.blKasserad = 0)

AND (tblTjanster.iUppehallID = 0)





to meny results in the sub query says the error

Any advise to get it work



//Kenneth

Re: SQL don't like the subquery Kenneth
8/31/2004 9:36:00 PM
It's right it's not unique, the result is more the one rows in the subquery
and it can happend when @iKundTjanstID = 1

but when the @iKundTjanstID > 1 then should the subquery not run., then
just take the @iKundTjanstID into the query.

Any advice?


//Kenneth





[quoted text, click to view]

Re: SQL don't like the subquery Kenneth
9/1/2004 7:30:52 PM
Thanks works as I want

//Kenneth

[quoted text, click to view]

AddThis Social Bookmark Button