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 2008 Forums
 Transact-SQL (2008)
 Subquery Error!!!!

Author  Topic 

prashantdighe
Starting Member

21 Posts

Posted - 2012-05-13 : 23:50:26
Hi all I m trying to get all value from same table but on different conditions(using where clause) so tried first column named Session_Taken_by

alter PROCEDURE [dbo].[Pivot_Report_Rating_only_Day]
(
@P_Name Varchar(MAX)
)

AS BEGIN

declare @query1 nvarchar(200)
set @query1=(select [Session_taken_By] from Program_rating where Program_name=@P_Name group by Session_taken_By,Session_Title)
EXEC sp_executesql @query1
end

but it shows following error

Msg 512, Level 16, State 1, Procedure Pivot_Report_Rating_only_Day, Line 13
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-13 : 23:54:08
use FOR XML PATH method describe here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

prashantdighe
Starting Member

21 Posts

Posted - 2012-05-13 : 23:57:21
Can I use CASE for this purpose????
Go to Top of Page

prashantdighe
Starting Member

21 Posts

Posted - 2012-05-14 : 01:01:09
Please help!!!!!
SELECT
Contribution,
SUM(CASE
WHEN Contribution >= 4 AND Contribution <> 10
THEN Contribution
ELSE NULL
end) as Contr

FROM program_rating where Program_name=@P_name group by Session_taken_By,Session_Title

error!!!!!

Msg 8120, Level 16, State 1, Procedure Pivot_Report_Rating_only_Day, Line 12
Column 'program_rating.Contribution' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Go to Top of Page
   

- Advertisement -