473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

SP kills a query when put in a parameter... help?

This query executes fine by itself:
SELECT count(id) as countr, username FROM endeavor_search WHERE IN (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username;

When trying to put it in a variable within a stored procedure, it fails:
SET @savedSearches = (SELECT count(id) as countr, username FROM endeavor_search WHERE EXISTS (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username);

Error:
Server: Msg 116, Level 16, State 1, Procedure endeavor_sp_memberRecentActivity, Line 15
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


How to I fix this?
Jul 12 '07 #1
2 1368
You're selecting two variables :

SELECT count(id) as countr, username

...Of course you can't assign the result to a single variable !!!!

Also, It looks very likely that you would get multiple records as a result of the query. Again....Of course you can't assign the result to a single variable !!!!

It's not the parameter. It's the query.
Jul 12 '07 #2
Infide
28
This query executes fine by itself:
SELECT count(id) as countr, username FROM endeavor_search WHERE IN (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username;

When trying to put it in a variable within a stored procedure, it fails:
SET @savedSearches = (SELECT count(id) as countr, username FROM endeavor_search WHERE EXISTS (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username);

Error:
Server: Msg 116, Level 16, State 1, Procedure endeavor_sp_memberRecentActivity, Line 15
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


How to I fix this?
In my world, this is better practice:
SELECT @SavedSearches = count(id), username
from endeavor_memberinfo
where something = something

Because this allows you to do this:

SELECT @SavedSearches = count(id),
@username = username
from endeavor_memberinfo
where something = something


"SELECT count(id) as countr, username FROM endeavor_search WHERE IN (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username;"

Instead try:

SELECT count(id) as countr, username FROM endeavor_search WHERE username IN (SELECT username FROM endeavor_memberInfo WHERE workingWith = @workingWithID) AND searchDate > @maxDate GROUP BY username;
Jul 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MX1 | last post by:
Simpler way to ask question from my previous post. I wrote a query and it has a paramter field in it. I want to enter a date with the current year. If it I put in 6/30/2003, it works great. If I...
3
by: Ryan Hubbard | last post by:
I would like to run a query from VBA. The query will be one with parameters. Is there a way to run the query and have Access prompt for the values like it does if I where to execute it through...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
2
by: rg | last post by:
Hi all, I have query about passing a parameter from form to a query. My situation is as follows: I have a query that pulls up some data from a table, however there is a condition that must...
1
by: jnikle | last post by:
I have a parameter query named "qry_employee_info_reports" that I need to run in the OnOpen event of a form. I'm after its total number of records. The query's got several joins in it, and one of...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
0
by: cht13er | last post by:
Good day all, I'm a newish VBA coder who was taught from Google Groups - so thanks to you all very much! I have run into a minor problem, I hope you can give me some help ... I'm running office...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.