SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Need help in fixing the query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kishoremcp
Starting Member

India
39 Posts

Posted - 01/28/2014 :  03:55:46  Show Profile  Reply with Quote
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

Edited by - kishoremcp on 01/28/2014 03:57:30

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

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

or are you looking for CSV value of @GRP ?


KH
Time is always against us

Go to Top of Page

kishoremcp
Starting Member

India
39 Posts

Posted - 01/28/2014 :  08:12:56  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 01/29/2014 :  04:22:57  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000