| Author |
Topic  |
|
|
eurob
Posting Yak Master
USA
100 Posts |
Posted - 08/31/2005 : 12:38:57
|
declare @a int select clientid,@a from mytable
I get the error : "A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations."
How can be worked around this issue ?
Thanks
robert |
|
|
SamC
White Water Yakist
USA
3459 Posts |
Posted - 08/31/2005 : 14:30:20
|
| SELECT @a = ClientID FROM MyTable |
Edited by - SamC on 08/31/2005 14:30:35 |
 |
|
|
eurob
Posting Yak Master
USA
100 Posts |
Posted - 08/31/2005 : 14:59:45
|
sorry,
i forgot something
declare @a int select clientid,@a = sum(items) from mytable
I get the error : "A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations."
robert |
 |
|
|
SamC
White Water Yakist
USA
3459 Posts |
Posted - 08/31/2005 : 16:01:55
|
Gotta use two steps. It makes sense.
SELECT @a = sum(items) from MyTable
SELECT ClientID FROM MyTable
Take a look and think about why doing both in a single step is a conflict. |
 |
|
|
eurob
Posting Yak Master
USA
100 Posts |
Posted - 09/01/2005 : 07:53:55
|
But I need the sum grouped by client, so I need to have it in one select.
robert |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 09/01/2005 : 08:43:56
|
Try this
SELECT @a = sum(items) from MyTable where Clienid=someId
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
anandc
Starting Member
India
20 Posts |
Posted - 09/01/2005 : 08:44:35
|
You may use the query like this... SELECT clientid, SUM(items) as A FROM mytable
- Anand |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 09/01/2005 : 08:50:53
|
quote: Originally posted by anandc
You may use the query like this... SELECT clientid, SUM(items) as A FROM mytable
- Anand
That should be SELECT clientid, SUM(items) as A FROM mytable group by Clientid
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
eurob
Posting Yak Master
USA
100 Posts |
Posted - 09/01/2005 : 10:04:18
|
quote:
SELECT @a = sum(items) from MyTable where Clientid=someId
This does not work, I get the same error msg as I got with my first post. I guess I would have to work with a temp table ? I need to use variables because within the select I want to add and subtract later on.
robert |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 09/01/2005 : 10:11:25
|
Can you post some sample data and the result you want?
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/01/2005 : 10:57:30
|
What's the problem you are wanting to solve?
When I look at your example:
declare @a int
select clientid,@a = sum(items) from mytable
it looks like you are trying to output "clientid", but "keep" the @a total for some further processing - and at that point I am sure I have misunderstood your problem!!
Kristen |
 |
|
|
ke.neelima
Starting Member
5 Posts |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
|
|
shijobaby
Starting Member
India
44 Posts |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
|
| |
Topic  |
|