I keep getting this error when running the below syntax. What causes this, and how can I resolve it?
Msg 512, Level 16, State 1, Procedure _do this, Line 114 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
SET @Query = 'update ##Results ' + 'set Count14 = ' + '(select count(*) from '+@fulllocation+' ' + 'where abcd in (select ' + 'namica_abcdfrom ' + 'masterlocale.' + 'dbo.main ' + 'where cfl_id in ' + '(''' +@store+ ''')) ' + 'and saledate between ''' + convert(varchar(100),@fromDate,101) + ''' ' + 'and ''' + convert(varchar(100),@toDate,101) + ''' ' + 'and supervisorapproved is null) ' + 'where storeName = ''' + @store + ''' ' exec (@Query) set @query = 'update ##Results ' + 'set Count0 = ' + '(select count(*) from '+@fulllocation+' ' + 'where abcd in (select ' + 'namica_abcd from ' + 'masterlocale.' + 'dbo.main ' + 'where frankflie_id in ' + '(''' +@store+ ''')) ' + 'and saledate between ''' + convert(varchar(100),@fromDate,101) + ''' ' + 'and ''' + convert(varchar(100),@toDate,101) + ''') ' + 'where storeName = ''' + @store+ ''' ' exec (@Query) set @query = 'update ##Results ' + 'set Count6 = ' + '(select count(*) from '+@fulllocation+' ' + 'where abcd in (select ' + 'namica_abcd from ' + 'masterlocale.' + 'dbo.main ' + 'where needmoreinfo is not null ' + 'and stepford_id in ' + '(''' +@store+ ''')) ' + 'and saledate between ''' + convert(varchar(100),@fromDate,101) + ''' ' + 'and ''' + convert(varchar(100),@toDate,101) + ''') ' + 'where storeName = ''' + @store+ ''' ' exec (@Query) set @query = 'update ##Results ' + 'set count3 = ' + '(select count(*) from '+@fulllocation+' ' + 'where abcd in (select ' + 'namica_abcdfrom ' + 'masterlocale.' + 'dbo.main ' + 'where prgl_prg_id in ' + '(''' + @store+ ''')) ' + 'and shipped_date is not null ' + 'and shipped_Date between ''' + convert(varchar(100),@fromDate,101) + ''' ' + 'and ''' + convert(varchar(100),@toDate,101) + ''') ' + 'where storeName = ''' +@store+ ''' ' exec (@Query)