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
 Script Library
 Need help in fixing the query

Author  Topic 

kishoremcp
Starting Member

41 Posts

Posted - 2014-01-28 : 03:55:46
Please help me in fixing the below query

Declare @GRP varchar(max) = 'All Groups'

if @GRP = 'All Groups'
begin
set @GRP = (select distinct ITS_Service_Area_Modified from 
[PMA_ODS].[Finance].[Missing_Time] 
where ITS_Service_Area_Modified != '' 
and ITS_Service_Area_Modified != 'CIO' 
UNION 
select distinct Cost_Center_CC_Service_Area_Desc from 
PMA_ODS.[Finance].[ITS_Expense_Compliance_Tracking] 
where Cost_Center_CC_Service_Area_Desc !='' 
and Cost_Center_CC_Service_Area_Desc !='CIO')
end
else
begin
set @GRP=@GRP
end

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. is the error

Regards
Kishore

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-28 : 04:55:23
there are multiple records return from your subquery. Which record do you want ?

or are you looking for CSV value of @GRP ?


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

Go to Top of Page

kishoremcp
Starting Member

41 Posts

Posted - 2014-01-28 : 08:12:56
I want all the records to take if @GRP is 'All Groups'.

Regards
Kishore
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-29 : 04:22:57
then you cant store them inside a variable as it can hold only a single value. you need to use a table variable instead.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -